Make it allocate less when running middleware chain
@@ -35,17 +35,15 @@ pub struct RequestContext<'a, Data> {
impl<'a, Data: Clone + Send> RequestContext<'a, Data> {
/// Consume this context, and run remaining middleware chain to completion.
pub fn next(mut self) -> FutureObj<'a, Response> {
- FutureObj::new(Box::new(
- async move {
if let Some((current, next)) = self.next_middleware.split_first() {
self.next_middleware = next;
- await!(current.handle(self))
+ current.handle(self)
} else {
- await!(self
- .endpoint
- .call(self.app_data.clone(), self.req, self.params))
+ FutureObj::new(Box::new(self.endpoint.call(
+ self.app_data.clone(),
+ self.req,
+ self.params,
+ )))
}
- },
- ))
}
}
