diff --git a/src/application.rs b/src/application.rs index dbb31a564..76ae1ba73 100644 --- a/src/application.rs +++ b/src/application.rs @@ -2,7 +2,7 @@ use std::cell::UnsafeCell; use std::collections::HashMap; use std::rc::Rc; -use handler::{FromRequest, Handler, Reply, Responder, RouteHandler, WrapHandler}; +use handler::{AsyncResult, FromRequest, Handler, Responder, RouteHandler, WrapHandler}; use header::ContentEncoding; use http::Method; use httprequest::HttpRequest; @@ -39,7 +39,7 @@ impl PipelineHandler for Inner { fn handle( &mut self, req: HttpRequest, htype: HandlerType, - ) -> Reply { + ) -> AsyncResult { match htype { HandlerType::Normal(idx) => { self.resources[idx].handle(req, Some(&mut self.default)) @@ -90,7 +90,7 @@ impl HttpApplication { } #[cfg(test)] - pub(crate) fn run(&mut self, mut req: HttpRequest) -> Reply { + pub(crate) fn run(&mut self, mut req: HttpRequest) -> AsyncResult { let tp = self.get_handler(&mut req); unsafe { &mut *self.inner.get() }.handle(req, tp) } diff --git a/src/extractor.rs b/src/extractor.rs index 9d707e22f..c83b238d2 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -12,7 +12,7 @@ use serde_urlencoded; use de::PathDeserializer; use error::{Error, ErrorBadRequest}; -use handler::{FromRequest, Reply}; +use handler::{AsyncResult, FromRequest}; use httpmessage::{HttpMessage, MessageBody, UrlEncoded}; use httprequest::HttpRequest; @@ -471,7 +471,7 @@ macro_rules! tuple_from_req ({$fut_type:ident, $(($n:tt, $T:ident)),+} => { { s: PhantomData, items: ($(Option<$T>,)+), - futs: ($(Option>,)+), + futs: ($(Option>,)+), } impl),+> Future for $fut_type diff --git a/src/fs.rs b/src/fs.rs index 9d2ea3015..348a99792 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -18,7 +18,7 @@ use mime; use mime_guess::{get_mime_type, guess_mime_type}; use error::Error; -use handler::{Handler, Reply, Responder, RouteHandler, WrapHandler}; +use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler}; use header; use http::{Method, StatusCode}; use httpmessage::HttpMessage; @@ -578,7 +578,7 @@ impl StaticFiles { } impl Handler for StaticFiles { - type Result = Result, Error>; + type Result = Result, Error>; fn handle(&mut self, req: HttpRequest) -> Self::Result { if !self.accessible { diff --git a/src/handler.rs b/src/handler.rs index 0a1bd9f59..632d63abb 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -23,12 +23,12 @@ pub trait Handler: 'static { /// Types that implement this trait can be used as the return type of a handler. pub trait Responder { /// The associated item which can be returned. - type Item: Into>; + type Item: Into>; /// The associated error which can be returned. type Error: Into; - /// Convert itself to `Reply` or `Error`. + /// Convert itself to `AsyncResult` or `Error`. fn respond_to(self, req: HttpRequest) -> Result; } @@ -40,7 +40,7 @@ pub trait FromRequest: Sized { type Config: Default; /// Future that resolves to a Self - type Result: Into>; + type Result: Into>; /// Convert request to a Self fn from_request(req: &HttpRequest, cfg: &Self::Config) -> Self::Result; @@ -93,10 +93,10 @@ where A: Responder, B: Responder, { - type Item = Reply; + type Item = AsyncResult; type Error = Error; - fn respond_to(self, req: HttpRequest) -> Result, Error> { + fn respond_to(self, req: HttpRequest) -> Result, Error> { match self { Either::A(a) => match a.respond_to(req) { Ok(val) => Ok(val.into()), @@ -182,26 +182,26 @@ where } } -/// Represents reply process. +/// Represents async result /// -/// Reply could be in tree different forms. -/// * Message(T) - ready item -/// * Error(Error) - error happen during reply process -/// * Future - reply process completes in the future -pub struct Reply(Option>); +/// Result could be in tree different forms. +/// * Ok(T) - ready item +/// * Err(E) - error happen during reply process +/// * Future - reply process completes in the future +pub struct AsyncResult(Option>); -impl Future for Reply { +impl Future for AsyncResult { type Item = I; type Error = E; fn poll(&mut self) -> Poll { let res = self.0.take().expect("use after resolve"); match res { - ReplyResult::Ok(msg) => Ok(Async::Ready(msg)), - ReplyResult::Err(err) => Err(err), - ReplyResult::Future(mut fut) => match fut.poll() { + AsyncResultItem::Ok(msg) => Ok(Async::Ready(msg)), + AsyncResultItem::Err(err) => Err(err), + AsyncResultItem::Future(mut fut) => match fut.poll() { Ok(Async::NotReady) => { - self.0 = Some(ReplyResult::Future(fut)); + self.0 = Some(AsyncResultItem::Future(fut)); Ok(Async::NotReady) } Ok(Async::Ready(msg)) => Ok(Async::Ready(msg)), @@ -211,43 +211,40 @@ impl Future for Reply { } } -pub(crate) enum ReplyResult { +pub(crate) enum AsyncResultItem { Ok(I), Err(E), Future(Box>), } -impl Reply { +impl AsyncResult { /// Create async response #[inline] - pub fn async(fut: F) -> Reply - where - F: Future + 'static, - { - Reply(Some(ReplyResult::Future(Box::new(fut)))) + pub fn async(fut: Box>) -> AsyncResult { + AsyncResult(Some(AsyncResultItem::Future(fut))) } /// Send response #[inline] - pub fn response>(response: R) -> Reply { - Reply(Some(ReplyResult::Ok(response.into()))) + pub fn ok>(ok: R) -> AsyncResult { + AsyncResult(Some(AsyncResultItem::Ok(ok.into()))) } /// Send error #[inline] - pub fn error>(err: R) -> Reply { - Reply(Some(ReplyResult::Err(err.into()))) + pub fn error>(err: R) -> AsyncResult { + AsyncResult(Some(AsyncResultItem::Err(err.into()))) } #[inline] - pub(crate) fn into(self) -> ReplyResult { + pub(crate) fn into(self) -> AsyncResultItem { self.0.expect("use after resolve") } #[cfg(test)] pub(crate) fn as_msg(&self) -> &I { match self.0.as_ref().unwrap() { - &ReplyResult::Ok(ref resp) => resp, + &AsyncResultItem::Ok(ref resp) => resp, _ => panic!(), } } @@ -255,35 +252,35 @@ impl Reply { #[cfg(test)] pub(crate) fn as_err(&self) -> Option<&E> { match self.0.as_ref().unwrap() { - &ReplyResult::Err(ref err) => Some(err), + &AsyncResultItem::Err(ref err) => Some(err), _ => None, } } } -impl Responder for Reply { - type Item = Reply; +impl Responder for AsyncResult { + type Item = AsyncResult; type Error = Error; - fn respond_to(self, _: HttpRequest) -> Result, Error> { + fn respond_to(self, _: HttpRequest) -> Result, Error> { Ok(self) } } impl Responder for HttpResponse { - type Item = Reply; + type Item = AsyncResult; type Error = Error; #[inline] - fn respond_to(self, _: HttpRequest) -> Result, Error> { - Ok(Reply(Some(ReplyResult::Ok(self)))) + fn respond_to(self, _: HttpRequest) -> Result, Error> { + Ok(AsyncResult(Some(AsyncResultItem::Ok(self)))) } } -impl From for Reply { +impl From for AsyncResult { #[inline] - fn from(resp: T) -> Reply { - Reply(Some(ReplyResult::Ok(resp))) + fn from(resp: T) -> AsyncResult { + AsyncResult(Some(AsyncResultItem::Ok(resp))) } } @@ -302,42 +299,42 @@ impl> Responder for Result { } } -impl> From, E>> for Reply { +impl> From, E>> for AsyncResult { #[inline] - fn from(res: Result, E>) -> Self { + fn from(res: Result, E>) -> Self { match res { Ok(val) => val, - Err(err) => Reply(Some(ReplyResult::Err(err.into()))), + Err(err) => AsyncResult(Some(AsyncResultItem::Err(err.into()))), } } } -impl> From> for Reply { +impl> From> for AsyncResult { #[inline] fn from(res: Result) -> Self { match res { - Ok(val) => Reply(Some(ReplyResult::Ok(val))), - Err(err) => Reply(Some(ReplyResult::Err(err.into()))), + Ok(val) => AsyncResult(Some(AsyncResultItem::Ok(val))), + Err(err) => AsyncResult(Some(AsyncResultItem::Err(err.into()))), } } } impl> From>, E>> - for Reply + for AsyncResult { #[inline] fn from(res: Result>, E>) -> Self { match res { - Ok(fut) => Reply(Some(ReplyResult::Future(fut))), - Err(err) => Reply(Some(ReplyResult::Err(err.into()))), + Ok(fut) => AsyncResult(Some(AsyncResultItem::Future(fut))), + Err(err) => AsyncResult(Some(AsyncResultItem::Err(err.into()))), } } } -impl From>> for Reply { +impl From>> for AsyncResult { #[inline] - fn from(fut: Box>) -> Reply { - Reply(Some(ReplyResult::Future(fut))) + fn from(fut: Box>) -> AsyncResult { + AsyncResult(Some(AsyncResultItem::Future(fut))) } } @@ -349,26 +346,26 @@ where I: Responder + 'static, E: Into + 'static, { - type Item = Reply; + type Item = AsyncResult; type Error = Error; #[inline] - fn respond_to(self, req: HttpRequest) -> Result, Error> { + fn respond_to(self, req: HttpRequest) -> Result, Error> { let fut = self.map_err(|e| e.into()) .then(move |r| match r.respond_to(req) { Ok(reply) => match reply.into().into() { - ReplyResult::Ok(resp) => ok(resp), + AsyncResultItem::Ok(resp) => ok(resp), _ => panic!("Nested async replies are not supported"), }, Err(e) => err(e), }); - Ok(Reply::async(fut)) + Ok(AsyncResult::async(Box::new(fut))) } } /// Trait defines object that could be registered as resource route pub(crate) trait RouteHandler: 'static { - fn handle(&mut self, req: HttpRequest) -> Reply; + fn handle(&mut self, req: HttpRequest) -> AsyncResult; } /// Route handler wrapper for Handler @@ -402,11 +399,11 @@ where R: Responder + 'static, S: 'static, { - fn handle(&mut self, req: HttpRequest) -> Reply { + fn handle(&mut self, req: HttpRequest) -> AsyncResult { let req2 = req.drop_state(); match self.h.handle(req).respond_to(req2) { Ok(reply) => reply.into(), - Err(err) => Reply::response(err.into()), + Err(err) => AsyncResult::ok(err.into()), } } } @@ -448,18 +445,18 @@ where E: Into + 'static, S: 'static, { - fn handle(&mut self, req: HttpRequest) -> Reply { + fn handle(&mut self, req: HttpRequest) -> AsyncResult { let req2 = req.drop_state(); let fut = (self.h)(req).map_err(|e| e.into()).then(move |r| { match r.respond_to(req2) { Ok(reply) => match reply.into().into() { - ReplyResult::Ok(resp) => ok(resp), + AsyncResultItem::Ok(resp) => ok(resp), _ => panic!("Nested async replies are not supported"), }, Err(e) => err(e), } }); - Reply::async(fut) + AsyncResult::async(Box::new(fut)) } } diff --git a/src/lib.rs b/src/lib.rs index 14e2cfc4e..5dd0309f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -200,7 +200,7 @@ pub mod dev { pub use body::BodyStream; pub use context::Drain; pub use extractor::{FormConfig, PayloadConfig}; - pub use handler::{Handler, Reply}; + pub use handler::{AsyncResult, Handler}; pub use httpmessage::{MessageBody, UrlEncoded}; pub use httpresponse::HttpResponseBuilder; pub use info::ConnectionInfo; diff --git a/src/pipeline.rs b/src/pipeline.rs index b6ddfff3f..14b050931 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -11,7 +11,7 @@ use application::Inner; use body::{Body, BodyStream}; use context::{ActorHttpContext, Frame}; use error::Error; -use handler::{Reply, ReplyResult}; +use handler::{AsyncResult, AsyncResultItem}; use header::ContentEncoding; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -28,8 +28,9 @@ pub(crate) enum HandlerType { pub(crate) trait PipelineHandler { fn encoding(&self) -> ContentEncoding; - fn handle(&mut self, req: HttpRequest, htype: HandlerType) - -> Reply; + fn handle( + &mut self, req: HttpRequest, htype: HandlerType, + ) -> AsyncResult; } pub(crate) struct Pipeline(PipelineInfo, PipelineState); @@ -321,12 +322,12 @@ struct WaitingResponse { impl WaitingResponse { #[inline] fn init( - info: &mut PipelineInfo, reply: Reply, + info: &mut PipelineInfo, reply: AsyncResult, ) -> PipelineState { match reply.into() { - ReplyResult::Err(err) => RunMiddlewares::init(info, err.into()), - ReplyResult::Ok(resp) => RunMiddlewares::init(info, resp), - ReplyResult::Future(fut) => PipelineState::Handler(WaitingResponse { + AsyncResultItem::Err(err) => RunMiddlewares::init(info, err.into()), + AsyncResultItem::Ok(resp) => RunMiddlewares::init(info, resp), + AsyncResultItem::Future(fut) => PipelineState::Handler(WaitingResponse { fut, _s: PhantomData, _h: PhantomData, diff --git a/src/resource.rs b/src/resource.rs index e78a45460..fb08afd94 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use http::{Method, StatusCode}; use smallvec::SmallVec; -use handler::{FromRequest, Handler, Reply, Responder}; +use handler::{AsyncResult, FromRequest, Handler, Responder}; use httprequest::HttpRequest; use httpresponse::HttpResponse; use middleware::Middleware; @@ -198,7 +198,7 @@ impl ResourceHandler { pub(crate) fn handle( &mut self, mut req: HttpRequest, default: Option<&mut ResourceHandler>, - ) -> Reply { + ) -> AsyncResult { for route in &mut self.routes { if route.check(&mut req) { return if self.middlewares.is_empty() { @@ -211,7 +211,7 @@ impl ResourceHandler { if let Some(resource) = default { resource.handle(req, None) } else { - Reply::response(HttpResponse::new(StatusCode::NOT_FOUND)) + AsyncResult::ok(HttpResponse::new(StatusCode::NOT_FOUND)) } } } diff --git a/src/route.rs b/src/route.rs index 7dda988ae..2558fa687 100644 --- a/src/route.rs +++ b/src/route.rs @@ -5,8 +5,8 @@ use std::rc::Rc; use futures::{Async, Future, Poll}; use error::Error; -use handler::{AsyncHandler, FromRequest, Handler, Reply, ReplyResult, Responder, - RouteHandler, WrapHandler}; +use handler::{AsyncHandler, AsyncResult, AsyncResultItem, FromRequest, Handler, + Responder, RouteHandler, WrapHandler}; use http::StatusCode; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -45,15 +45,15 @@ impl Route { } #[inline] - pub(crate) fn handle(&mut self, req: HttpRequest) -> Reply { + pub(crate) fn handle(&mut self, req: HttpRequest) -> AsyncResult { self.handler.handle(req) } #[inline] pub(crate) fn compose( &mut self, req: HttpRequest, mws: Rc>>>, - ) -> Reply { - Reply::async(Compose::new(req, mws, self.handler.clone())) + ) -> AsyncResult { + AsyncResult::async(Box::new(Compose::new(req, mws, self.handler.clone()))) } /// Add match predicate to route. @@ -243,7 +243,7 @@ impl InnerHandler { } #[inline] - pub fn handle(&self, req: HttpRequest) -> Reply { + pub fn handle(&self, req: HttpRequest) -> AsyncResult { // reason: handler is unique per thread, handler get called from async code only let h = unsafe { &mut *self.0.as_ref().get() }; h.handle(req) @@ -415,11 +415,13 @@ struct WaitingResponse { impl WaitingResponse { #[inline] - fn init(info: &mut ComposeInfo, reply: Reply) -> ComposeState { + fn init( + info: &mut ComposeInfo, reply: AsyncResult, + ) -> ComposeState { match reply.into() { - ReplyResult::Err(err) => RunMiddlewares::init(info, err.into()), - ReplyResult::Ok(resp) => RunMiddlewares::init(info, resp), - ReplyResult::Future(fut) => ComposeState::Handler(WaitingResponse { + AsyncResultItem::Err(err) => RunMiddlewares::init(info, err.into()), + AsyncResultItem::Ok(resp) => RunMiddlewares::init(info, resp), + AsyncResultItem::Future(fut) => ComposeState::Handler(WaitingResponse { fut, _s: PhantomData, }), diff --git a/src/scope.rs b/src/scope.rs index f48308f2a..bab2ac944 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use futures::{Async, Future, Poll}; use error::Error; -use handler::{FromRequest, Reply, ReplyResult, Responder, RouteHandler}; +use handler::{AsyncResult, AsyncResultItem, FromRequest, Responder, RouteHandler}; use http::Method; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -274,7 +274,7 @@ impl Scope { } impl RouteHandler for Scope { - fn handle(&mut self, mut req: HttpRequest) -> Reply { + fn handle(&mut self, mut req: HttpRequest) -> AsyncResult { let path = unsafe { &*(&req.match_info()["tail"] as *const _) }; let path = if path == "" { "/" } else { path }; @@ -287,12 +287,12 @@ impl RouteHandler for Scope { let resource = unsafe { &mut *resource.get() }; return resource.handle(req, Some(default)); } else { - return Reply::async(Compose::new( + return AsyncResult::async(Box::new(Compose::new( req, Rc::clone(&self.middlewares), Rc::clone(&resource), Some(Rc::clone(&self.default)), - )); + ))); } } } @@ -330,12 +330,12 @@ impl RouteHandler for Scope { if self.middlewares.is_empty() { default.handle(req, None) } else { - Reply::async(Compose::new( + AsyncResult::async(Box::new(Compose::new( req, Rc::clone(&self.middlewares), Rc::clone(&self.default), None, - )) + ))) } } } @@ -346,7 +346,7 @@ struct Wrapper { } impl RouteHandler for Wrapper { - fn handle(&mut self, req: HttpRequest) -> Reply { + fn handle(&mut self, req: HttpRequest) -> AsyncResult { self.scope .handle(req.change_state(Rc::clone(&self.state))) } @@ -521,11 +521,13 @@ struct WaitingResponse { impl WaitingResponse { #[inline] - fn init(info: &mut ComposeInfo, reply: Reply) -> ComposeState { + fn init( + info: &mut ComposeInfo, reply: AsyncResult, + ) -> ComposeState { match reply.into() { - ReplyResult::Ok(resp) => RunMiddlewares::init(info, resp), - ReplyResult::Err(err) => RunMiddlewares::init(info, err.into()), - ReplyResult::Future(fut) => ComposeState::Handler(WaitingResponse { + AsyncResultItem::Ok(resp) => RunMiddlewares::init(info, resp), + AsyncResultItem::Err(err) => RunMiddlewares::init(info, err.into()), + AsyncResultItem::Future(fut) => ComposeState::Handler(WaitingResponse { fut, _s: PhantomData, }), diff --git a/src/test.rs b/src/test.rs index 08d05ba8d..57edcbf0a 100644 --- a/src/test.rs +++ b/src/test.rs @@ -21,7 +21,7 @@ use application::{App, HttpApplication}; use body::Binary; use client::{ClientConnector, ClientRequest, ClientRequestBuilder}; use error::Error; -use handler::{Handler, ReplyResult, Responder}; +use handler::{AsyncResultItem, Handler, Responder}; use header::{Header, IntoHeaderValue}; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -593,19 +593,17 @@ impl TestRequest { /// with generated request. /// /// This method panics is handler returns actor or async result. - pub fn run>( - self, mut h: H, - ) -> Result>::Result as Responder>::Error> { + pub fn run>(self, mut h: H) -> Result { let req = self.finish(); let resp = h.handle(req.clone()); match resp.respond_to(req.drop_state()) { Ok(resp) => match resp.into().into() { - ReplyResult::Ok(resp) => Ok(resp), - ReplyResult::Err(err) => Ok(err.into()), - ReplyResult::Future(_) => panic!("Async handler is not supported."), + AsyncResultItem::Ok(resp) => Ok(resp), + AsyncResultItem::Err(err) => Err(err), + AsyncResultItem::Future(_) => panic!("Async handler is not supported."), }, - Err(err) => Err(err), + Err(err) => Err(err.into()), } } @@ -627,7 +625,7 @@ impl TestRequest { match core.run(fut) { Ok(r) => match r.respond_to(req.drop_state()) { Ok(reply) => match reply.into().into() { - ReplyResult::Ok(resp) => Ok(resp), + AsyncResultItem::Ok(resp) => Ok(resp), _ => panic!("Nested async replies are not supported"), }, Err(e) => Err(e), diff --git a/src/with.rs b/src/with.rs index 3ee9a6a10..0f7d07744 100644 --- a/src/with.rs +++ b/src/with.rs @@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut}; use std::rc::Rc; use error::Error; -use handler::{FromRequest, Handler, Reply, ReplyResult, Responder}; +use handler::{AsyncResult, AsyncResultItem, FromRequest, Handler, Responder}; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -82,7 +82,7 @@ where T: FromRequest + 'static, S: 'static, { - type Result = Reply; + type Result = AsyncResult; fn handle(&mut self, req: HttpRequest) -> Self::Result { let mut fut = WithHandlerFut { @@ -95,9 +95,9 @@ where }; match fut.poll() { - Ok(Async::Ready(resp)) => Reply::response(resp), - Ok(Async::NotReady) => Reply::async(fut), - Err(e) => Reply::error::(e), + Ok(Async::Ready(resp)) => AsyncResult::ok(resp), + Ok(Async::NotReady) => AsyncResult::async(Box::new(fut)), + Err(e) => AsyncResult::error::(e), } } } @@ -136,9 +136,9 @@ where self.started = true; let reply = T::from_request(&self.req, self.cfg.as_ref()).into(); match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.fut1 = Some(fut); return self.poll(); } @@ -157,9 +157,9 @@ where }; match item.into() { - ReplyResult::Err(err) => Err(err), - ReplyResult::Ok(resp) => Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => Err(err), + AsyncResultItem::Ok(resp) => Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut2 = Some(fut); self.poll() } @@ -207,7 +207,7 @@ where T2: FromRequest + 'static, S: 'static, { - type Result = Reply; + type Result = AsyncResult; fn handle(&mut self, req: HttpRequest) -> Self::Result { let mut fut = WithHandlerFut2 { @@ -222,9 +222,9 @@ where fut3: None, }; match fut.poll() { - Ok(Async::Ready(resp)) => Reply::response(resp), - Ok(Async::NotReady) => Reply::async(fut), - Err(e) => Reply::response(e), + Ok(Async::Ready(resp)) => AsyncResult::ok(resp), + Ok(Async::NotReady) => AsyncResult::async(Box::new(fut)), + Err(e) => AsyncResult::ok(e), } } } @@ -268,9 +268,9 @@ where self.started = true; let reply = T1::from_request(&self.req, self.cfg1.as_ref()).into(); let item1 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.fut1 = Some(fut); return self.poll(); } @@ -278,9 +278,9 @@ where let reply = T2::from_request(&self.req, self.cfg2.as_ref()).into(); let item2 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item = Some(item1); self.fut2 = Some(fut); return self.poll(); @@ -290,9 +290,9 @@ where let hnd: &mut F = unsafe { &mut *self.hnd.get() }; match (*hnd)(item1, item2).respond_to(self.req.drop_state()) { Ok(item) => match item.into().into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut3 = Some(fut); return self.poll(); } @@ -306,9 +306,9 @@ where Async::Ready(item) => { let reply = T2::from_request(&self.req, self.cfg2.as_ref()).into(); let item2 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item = Some(item); self.fut2 = Some(fut); return self.poll(); @@ -318,9 +318,9 @@ where let hnd: &mut F = unsafe { &mut *self.hnd.get() }; match (*hnd)(item, item2).respond_to(self.req.drop_state()) { Ok(item) => match item.into().into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut3 = Some(fut); return self.poll(); } @@ -346,9 +346,9 @@ where }; match item.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => self.fut3 = Some(fut), + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => self.fut3 = Some(fut), } self.poll() @@ -404,7 +404,7 @@ where T3: 'static, S: 'static, { - type Result = Reply; + type Result = AsyncResult; fn handle(&mut self, req: HttpRequest) -> Self::Result { let mut fut = WithHandlerFut3 { @@ -422,9 +422,9 @@ where fut4: None, }; match fut.poll() { - Ok(Async::Ready(resp)) => Reply::response(resp), - Ok(Async::NotReady) => Reply::async(fut), - Err(e) => Reply::response(e), + Ok(Async::Ready(resp)) => AsyncResult::ok(resp), + Ok(Async::NotReady) => AsyncResult::async(Box::new(fut)), + Err(e) => AsyncResult::error(e), } } } @@ -473,9 +473,9 @@ where self.started = true; let reply = T1::from_request(&self.req, self.cfg1.as_ref()).into(); let item1 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.fut1 = Some(fut); return self.poll(); } @@ -483,9 +483,9 @@ where let reply = T2::from_request(&self.req, self.cfg2.as_ref()).into(); let item2 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item1 = Some(item1); self.fut2 = Some(fut); return self.poll(); @@ -494,9 +494,9 @@ where let reply = T3::from_request(&self.req, self.cfg3.as_ref()).into(); let item3 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item1 = Some(item1); self.item2 = Some(item2); self.fut3 = Some(fut); @@ -507,9 +507,9 @@ where let hnd: &mut F = unsafe { &mut *self.hnd.get() }; match (*hnd)(item1, item2, item3).respond_to(self.req.drop_state()) { Ok(item) => match item.into().into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut4 = Some(fut); return self.poll(); } @@ -525,9 +525,9 @@ where self.fut1.take(); let reply = T2::from_request(&self.req, self.cfg2.as_ref()).into(); let item2 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.fut2 = Some(fut); return self.poll(); } @@ -535,9 +535,9 @@ where let reply = T3::from_request(&self.req, self.cfg3.as_ref()).into(); let item3 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item2 = Some(item2); self.fut3 = Some(fut); return self.poll(); @@ -548,9 +548,9 @@ where .respond_to(self.req.drop_state()) { Ok(item) => match item.into().into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut4 = Some(fut); return self.poll(); } @@ -568,9 +568,9 @@ where self.fut2.take(); let reply = T3::from_request(&self.req, self.cfg3.as_ref()).into(); let item3 = match reply.into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(msg) => msg, - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(msg) => msg, + AsyncResultItem::Future(fut) => { self.item2 = Some(item); self.fut3 = Some(fut); return self.poll(); @@ -581,9 +581,9 @@ where .respond_to(self.req.drop_state()) { Ok(item) => match item.into().into() { - ReplyResult::Err(err) => return Err(err), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => { + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => { self.fut4 = Some(fut); return self.poll(); } @@ -612,9 +612,9 @@ where }; match item.into() { - ReplyResult::Err(err) => return Ok(Async::Ready(err.into())), - ReplyResult::Ok(resp) => return Ok(Async::Ready(resp)), - ReplyResult::Future(fut) => self.fut4 = Some(fut), + AsyncResultItem::Err(err) => return Err(err), + AsyncResultItem::Ok(resp) => return Ok(Async::Ready(resp)), + AsyncResultItem::Future(fut) => self.fut4 = Some(fut), } self.poll()