diff --git a/src/service/apply.rs b/src/service/apply.rs index 508efb17..0fa8d77b 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -1,7 +1,7 @@ use std::marker::PhantomData; use futures::{Async, Future, Poll}; -use {NewService, Service, IntoNewService}; +use {IntoNewService, NewService, Service}; /// `ApplyService` service combinator pub struct ApplyService { diff --git a/src/service/mod.rs b/src/service/mod.rs index 81b6bff1..fe9a2443 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -1,4 +1,4 @@ -use futures::IntoFuture; +use futures::{Future, IntoFuture}; mod and_then; mod apply; @@ -20,13 +20,23 @@ pub use self::map_request::{MapReq, MapReqNewService}; use {NewService, Service}; pub trait ServiceExt: Service { - fn and_then(self, new_service: F) -> AndThen + fn apply(self, f: F) -> ApplyService + where + Self: Sized, + Self::Error: Into, + F: Fn(Req, &mut Self) -> R, + R: Future, + { + ApplyService::new(f, self) + } + + fn and_then(self, service: F) -> AndThen where Self: Sized, F: IntoService, B: Service, { - AndThen::new(self, new_service.into_service()) + AndThen::new(self, service.into_service()) } fn map(self, f: F) -> Map @@ -47,6 +57,16 @@ pub trait ServiceExt: Service { } pub trait NewServiceExt: NewService { + fn apply(self, f: F) -> Apply + where + Self: Sized, + Self::Error: Into, + F: Fn(Req, &mut Self::Service) -> R + Clone, + R: Future, + { + Apply::new(f, self) + } + fn and_then(self, new_service: F) -> AndThenNewService where Self: Sized,