use futures::IntoFuture; mod and_then; mod apply; mod fn_service; mod fn_state_service; mod map; mod map_err; mod map_init_err; mod map_request; pub use self::and_then::{AndThen, AndThenNewService}; pub use self::apply::{Apply, ApplyService}; 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 use self::map_request::{MapReq, MapReqNewService}; use {NewService, Service}; 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 Self: Sized, F: IntoNewService, B: NewService< Request = Self::Response, Error = Self::Error, InitError = Self::InitError, >, { AndThenNewService::new(self, new_service) } fn map(self, f: F) -> MapNewService where Self: Sized, F: Fn(Self::Response) -> R, { MapNewService::new(self, f) } fn map_err(self, f: F) -> MapErrNewService where Self: Sized, F: Fn(Self::Error) -> E, { MapErrNewService::new(self, f) } fn map_request(self, f: F) -> MapReqNewService where Self: Sized, F: Fn(R) -> Self::Request, { MapReqNewService::new(self, f) } fn map_init_err(self, f: F) -> MapInitErr where Self: Sized, F: Fn(Self::InitError) -> E, { MapInitErr::new(self, f) } } impl ServiceExt for T {} impl NewServiceExt for T {} /// Trait for types that can be converted to a Service pub trait IntoService where T: Service, { /// Create service fn into_service(self) -> T; } /// Trait for types that can be converted to a Service pub trait IntoNewService where T: NewService, { /// Create service fn into_new_service(self) -> T; } impl IntoService for T where T: Service, { fn into_service(self) -> T { self } } impl IntoNewService for T where T: NewService, { fn into_new_service(self) -> T { self } } impl IntoService> for F where F: Fn(Req) -> Fut + 'static, Fut: IntoFuture, { fn into_service(self) -> FnService { FnService::new(self) } }