diff --git a/.travis.yml b/.travis.yml index d994a80d4..1d3c227a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,6 @@ before_script: script: - cargo clean - - cargo check - cargo test -- --nocapture # Upload docs diff --git a/src/app.rs b/src/app.rs index 2a2380b21..c9c23d9cb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -188,13 +188,13 @@ where > where M: NewTransform< - AppService

, + AppRouting

, Request = ServiceRequest

, Response = ServiceResponse, Error = (), InitError = (), >, - F: IntoNewTransform>, + F: IntoNewTransform>, { let fref = Rc::new(RefCell::new(None)); let endpoint = ApplyNewService::new(mw, AppEntry::new(fref.clone())); @@ -253,7 +253,7 @@ pub struct AppRouter { default: Option>>, defaults: Vec>>>>>, endpoint: T, - factory_ref: Rc>>>, + factory_ref: Rc>>>, extensions: Extensions, state: Vec>, _t: PhantomData<(P, B)>, @@ -465,7 +465,7 @@ where } // set factory - *self.factory_ref.borrow_mut() = Some(AppFactory { + *self.factory_ref.borrow_mut() = Some(AppRoutingFactory { services: Rc::new(self.services), }); @@ -478,25 +478,25 @@ where } } -pub struct AppFactory

{ +pub struct AppRoutingFactory

{ services: Rc)>>, } -impl NewService for AppFactory

{ +impl NewService for AppRoutingFactory

{ type Request = ServiceRequest

; type Response = ServiceResponse; type Error = (); type InitError = (); - type Service = AppService

; - type Future = CreateAppService

; + type Service = AppRouting

; + type Future = AppRoutingFactoryResponse

; fn new_service(&self, _: &()) -> Self::Future { - CreateAppService { + AppRoutingFactoryResponse { fut: self .services .iter() .map(|(path, service)| { - CreateAppServiceItem::Future( + CreateAppRoutingItem::Future( Some(path.clone()), service.new_service(&()), ) @@ -510,17 +510,17 @@ type HttpServiceFut

= Box, Error = ()>>; /// Create app service #[doc(hidden)] -pub struct CreateAppService

{ - fut: Vec>, +pub struct AppRoutingFactoryResponse

{ + fut: Vec>, } -enum CreateAppServiceItem

{ +enum CreateAppRoutingItem

{ Future(Option, HttpServiceFut

), Service(ResourceDef, HttpService

), } -impl

Future for CreateAppService

{ - type Item = AppService

; +impl

Future for AppRoutingFactoryResponse

{ + type Item = AppRouting

; type Error = (); fn poll(&mut self) -> Poll { @@ -529,7 +529,7 @@ impl

Future for CreateAppService

{ // poll http services for item in &mut self.fut { let res = match item { - CreateAppServiceItem::Future(ref mut path, ref mut fut) => { + CreateAppRoutingItem::Future(ref mut path, ref mut fut) => { match fut.poll()? { Async::Ready(service) => Some((path.take().unwrap(), service)), Async::NotReady => { @@ -538,11 +538,11 @@ impl

Future for CreateAppService

{ } } } - CreateAppServiceItem::Service(_, _) => continue, + CreateAppRoutingItem::Service(_, _) => continue, }; if let Some((path, service)) = res { - *item = CreateAppServiceItem::Service(path, service); + *item = CreateAppRoutingItem::Service(path, service); } } @@ -552,14 +552,14 @@ impl

Future for CreateAppService

{ .drain(..) .fold(Router::build(), |mut router, item| { match item { - CreateAppServiceItem::Service(path, service) => { + CreateAppRoutingItem::Service(path, service) => { router.rdef(path, service) } - CreateAppServiceItem::Future(_, _) => unreachable!(), + CreateAppRoutingItem::Future(_, _) => unreachable!(), } router }); - Ok(Async::Ready(AppService { + Ok(Async::Ready(AppRouting { router: router.finish(), ready: None, })) @@ -569,12 +569,12 @@ impl

Future for CreateAppService

{ } } -pub struct AppService

{ +pub struct AppRouting

{ router: Router>, ready: Option<(ServiceRequest

, ResourceInfo)>, } -impl

Service for AppService

{ +impl

Service for AppRouting

{ type Request = ServiceRequest

; type Response = ServiceResponse; type Error = (); @@ -599,12 +599,13 @@ impl

Service for AppService

{ } #[doc(hidden)] +/// Wrapper service for routing pub struct AppEntry

{ - factory: Rc>>>, + factory: Rc>>>, } impl

AppEntry

{ - fn new(factory: Rc>>>) -> Self { + fn new(factory: Rc>>>) -> Self { AppEntry { factory } } } @@ -614,8 +615,8 @@ impl NewService for AppEntry

{ type Response = ServiceResponse; type Error = (); type InitError = (); - type Service = AppService

; - type Future = CreateAppService

; + type Service = AppRouting

; + type Future = AppRoutingFactoryResponse

; fn new_service(&self, _: &()) -> Self::Future { self.factory.borrow_mut().as_mut().unwrap().new_service(&()) @@ -644,16 +645,19 @@ impl Service for AppChain { type Error = (); type Future = FutureResult; + #[inline] fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) } + #[inline] fn call(&mut self, req: Self::Request) -> Self::Future { ok(req) } } -/// Service factory to convert `Request` to a `ServiceRequest` +/// Service factory to convert `Request` to a `ServiceRequest`. +/// It also executes state factories. pub struct AppInit where C: NewService, Response = ServiceRequest

>,