Skip to content

Commit 7cf6123

Browse files
committed
Addressing review comments
- Remove root_context_id from RootContext's create_http_stream and create_http_context calls - Move EmptyHttpContext after HttpContext declaration - Reorder trait impl's in examples to be consistent Signed-off-by: Daniel Grimm <dgrimm@redhat.com>
1 parent 94ecd03 commit 7cf6123

File tree

6 files changed

+33
-37
lines changed

6 files changed

+33
-37
lines changed

examples/hello_world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ pub fn _start() {
3030

3131
struct HelloWorld;
3232

33-
impl Context for HelloWorld {}
34-
3533
impl RootContext for HelloWorld {
3634
fn on_vm_start(&mut self, _: usize) -> bool {
3735
info!("Hello, World!");
@@ -54,3 +52,5 @@ impl RootContext for HelloWorld {
5452
}
5553
}
5654
}
55+
56+
impl Context for HelloWorld {}

examples/http_auth_random.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl RootContext for HttpAuthRandomRoot {
3131
ContextType::HttpContext
3232
}
3333

34-
fn create_http_context(&self, _root_context_id: u32, _context_id: u32) -> Box<dyn HttpContext> {
34+
fn create_http_context(&self, _context_id: u32) -> Box<dyn HttpContext> {
3535
Box::new(HttpAuthRandom)
3636
}
3737
}

examples/http_body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ impl RootContext for HttpBodyRoot {
2929
ContextType::HttpContext
3030
}
3131

32-
fn create_http_context(&self, _context_id: u32, _root_context_id: u32) -> Box<dyn HttpContext> {
32+
fn create_http_context(&self, _context_id: u32) -> Box<dyn HttpContext> {
3333
Box::new(HttpBody)
3434
}
3535
}
3636

3737
impl Context for HttpBodyRoot {}
3838

39-
impl Context for HttpBody {}
40-
4139
impl HttpContext for HttpBody {
4240
fn on_http_response_headers(&mut self, _: usize) -> Action {
4341
// If there is a Content-Length header and we change the length of
@@ -67,3 +65,5 @@ impl HttpContext for HttpBody {
6765
Action::Continue
6866
}
6967
}
68+
69+
impl Context for HttpBody {}

examples/http_headers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@ pub fn _start() {
2424

2525
struct HttpHeadersRoot;
2626

27-
impl Context for HttpHeadersRoot {}
28-
2927
impl RootContext for HttpHeadersRoot {
3028
fn get_type(&self) -> ContextType {
3129
ContextType::HttpContext
3230
}
3331

34-
fn create_http_context(&self, _context_id: u32, _root_context_id: u32) -> Box<dyn HttpContext> {
32+
fn create_http_context(&self, _context_id: u32) -> Box<dyn HttpContext> {
3533
Box::new(HttpHeaders {
3634
context_id: _context_id,
3735
})
3836
}
3937
}
4038

39+
impl Context for HttpHeadersRoot {}
40+
4141
struct HttpHeaders {
4242
context_id: u32,
4343
}
4444

45-
impl Context for HttpHeaders {}
46-
4745
impl HttpContext for HttpHeaders {
4846
fn on_http_request_headers(&mut self, _: usize) -> Action {
4947
for (name, value) in &self.get_http_request_headers() {
@@ -74,3 +72,5 @@ impl HttpContext for HttpHeaders {
7472
trace!("#{} completed.", self.context_id);
7573
}
7674
}
75+
76+
impl Context for HttpHeaders {}

src/dispatcher.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ impl Dispatcher {
6060
self.new_root.set(Some(callback));
6161
}
6262

63+
fn register_callout(&self, token_id: u32) {
64+
if self
65+
.callouts
66+
.borrow_mut()
67+
.insert(token_id, self.active_id.get())
68+
.is_some()
69+
{
70+
panic!("duplicate token_id")
71+
}
72+
}
73+
6374
fn create_root_context(&self, context_id: u32) {
6475
let new_context = match self.new_root.get() {
6576
Some(f) => f(context_id),
@@ -77,7 +88,7 @@ impl Dispatcher {
7788

7889
fn create_stream_context(&self, context_id: u32, root_context_id: u32) {
7990
let new_context = match self.roots.borrow().get(&root_context_id) {
80-
Some(root_context) => root_context.create_stream_context(context_id, root_context_id),
91+
Some(root_context) => root_context.create_stream_context(context_id),
8192
None => panic!("invalid root_context_id"),
8293
};
8394
if self
@@ -92,7 +103,7 @@ impl Dispatcher {
92103

93104
fn create_http_context(&self, context_id: u32, root_context_id: u32) {
94105
let new_context = match self.roots.borrow().get(&root_context_id) {
95-
Some(root_context) => root_context.create_http_context(context_id, root_context_id),
106+
Some(root_context) => root_context.create_http_context(context_id),
96107
None => panic!("invalid root_context_id"),
97108
};
98109
if self
@@ -105,17 +116,6 @@ impl Dispatcher {
105116
}
106117
}
107118

108-
fn register_callout(&self, token_id: u32) {
109-
if self
110-
.callouts
111-
.borrow_mut()
112-
.insert(token_id, self.active_id.get())
113-
.is_some()
114-
{
115-
panic!("duplicate token_id")
116-
}
117-
}
118-
119119
fn on_create_context(&self, context_id: u32, root_context_id: u32) {
120120
if root_context_id == 0 {
121121
self.create_root_context(context_id);
@@ -125,10 +125,10 @@ impl Dispatcher {
125125
ContextType::StreamContext => {
126126
self.create_stream_context(context_id, root_context_id)
127127
}
128-
ContextType::RootContext => panic!("missing constructors"),
128+
ContextType::RootContext => panic!("missing ContextType on root_context"),
129129
}
130130
} else {
131-
panic!("missing constructors")
131+
panic!("invalid root_context_id");
132132
}
133133
}
134134

src/traits.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,11 @@ pub trait RootContext: Context {
122122

123123
fn on_log(&mut self) {}
124124

125-
fn create_http_context(&self, _context_id: u32, _root_context_id: u32) -> Box<dyn HttpContext> {
125+
fn create_http_context(&self, _context_id: u32) -> Box<dyn HttpContext> {
126126
Box::new(EmptyHttpContext)
127127
}
128128

129-
fn create_stream_context(
130-
&self,
131-
_context_id: u32,
132-
_root_context_id: u32,
133-
) -> Box<dyn StreamContext> {
129+
fn create_stream_context(&self, _context_id: u32) -> Box<dyn StreamContext> {
134130
Box::new(EmptyStreamContext)
135131
}
136132

@@ -175,11 +171,6 @@ pub trait StreamContext: Context {
175171
fn on_log(&mut self) {}
176172
}
177173

178-
struct EmptyHttpContext;
179-
180-
impl HttpContext for EmptyHttpContext {}
181-
impl Context for EmptyHttpContext {}
182-
183174
struct EmptyStreamContext;
184175

185176
impl StreamContext for EmptyStreamContext {}
@@ -329,3 +320,8 @@ pub trait HttpContext: Context {
329320

330321
fn on_log(&mut self) {}
331322
}
323+
324+
struct EmptyHttpContext;
325+
326+
impl HttpContext for EmptyHttpContext {}
327+
impl Context for EmptyHttpContext {}

0 commit comments

Comments
 (0)