diff --git a/src/service/mod.rs b/src/service/mod.rs index 7cfca59b4..553f35e81 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -9,12 +9,39 @@ mod map_err; mod map_init_err; pub use self::and_then::{AndThen, AndThenNewService}; -pub use self::fn_service::{FnService, FnNewService}; -pub use self::fn_state_service::{FnStateService, FnStateNewService}; +pub use self::fn_service::{FnNewService, FnService}; +pub use self::fn_state_service::{FnStateNewService, FnStateService}; pub use self::map::{Map, MapNewService}; pub use self::map_err::{MapErr, MapErrNewService}; pub use self::map_init_err::MapInitErr; +pub trait ServiceExt: Service { + fn and_then(self, new_service: F) -> AndThen + where + Self: Sized, + F: IntoService, + B: Service, + { + AndThen::new(self, new_service.into_service()) + } + + fn map(self, f: F) -> Map + where + Self: Sized, + F: Fn(Self::Response) -> R, + { + Map::new(self, f) + } + + fn map_err(self, f: F) -> MapErr + where + Self: Sized, + F: Fn(Self::Error) -> E, + { + MapErr::new(self, f) + } +} + pub trait NewServiceExt: NewService { fn and_then(self, new_service: F) -> AndThenNewService where @@ -54,6 +81,7 @@ pub trait NewServiceExt: NewService { } } +impl ServiceExt for T {} impl NewServiceExt for T {} /// Trait for types that can be converted to a Service @@ -62,7 +90,7 @@ where T: Service, { /// Create service - fn into(self) -> T; + fn into_service(self) -> T; } /// Trait for types that can be converted to a Service @@ -78,7 +106,7 @@ impl IntoService for T where T: Service, { - fn into(self) -> T { + fn into_service(self) -> T { self } } @@ -97,7 +125,7 @@ where F: Fn(Req) -> Fut + 'static, Fut: IntoFuture, { - fn into(self) -> FnService { + fn into_service(self) -> FnService { FnService::new(self) } }