use futures::IntoFuture; use tower_service::{NewService, Service}; mod and_then; mod fn_service; mod fn_state_service; mod map; 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::map::{Map, MapNewService}; pub use self::map_err::{MapErr, MapErrNewService}; pub use self::map_init_err::MapInitErr; 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_init_err(self, f: F) -> MapInitErr where Self: Sized, F: Fn(Self::InitError) -> E, { MapInitErr::new(self, f) } } impl NewServiceExt for T {} /// Trait for types that can be converted to a Service pub trait IntoService where T: Service, { /// Create service fn into(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(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(self) -> FnService { FnService::new(self) } }