Trait ntex::ServiceFactory
source · pub trait ServiceFactory<Req, Cfg = ()> {
type Response;
type Error;
type Service: Service<Req, Response = Self::Response, Error = Self::Error>;
type InitError;
type Future<'f>: Future<Output = Result<Self::Service, Self::InitError>>
where Cfg: 'f,
Self: 'f;
// Required method
fn create(&self, cfg: Cfg) -> Self::Future<'_>;
// Provided methods
fn pipeline(&self, cfg: Cfg) -> CreatePipeline<'_, Self, Req, Cfg> ⓘ
where Self: Sized { ... }
fn map<F, Res>(
self,
f: F
) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
where Self: Sized,
F: Fn(Self::Response) -> Res + Clone { ... }
fn map_err<F, E>(
self,
f: F
) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized,
F: Fn(Self::Error) -> E + Clone { ... }
fn map_init_err<F, E>(
self,
f: F
) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized,
F: Fn(Self::InitError) -> E + Clone { ... }
}
Expand description
Factory for creating Service
s.
This is useful for cases where new Service
s must be produced. One case is a TCP server
listener: a listener accepts new connections, constructs a new Service
for each using
the ServiceFactory
trait, and uses the new Service
to process inbound requests on that
new connection.
Config
is a service factory configuration type.
Simple factories may be able to use fn_factory
or fn_factory_with_config
to
reduce boilerplate.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn pipeline(&self, cfg: Cfg) -> CreatePipeline<'_, Self, Req, Cfg> ⓘwhere
Self: Sized,
fn pipeline(&self, cfg: Cfg) -> CreatePipeline<'_, Self, Req, Cfg> ⓘwhere
Self: Sized,
Create and return a new service value asynchronously and wrap into a container
sourcefn map<F, Res>(
self,
f: F
) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
fn map<F, Res>( self, f: F ) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
Map this service’s output to a different type, returning a new service of the resulting type.
sourcefn map_err<F, E>(
self,
f: F
) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
fn map_err<F, E>( self, f: F ) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
Map this service’s error to a different error, returning a new service.
sourcefn map_init_err<F, E>(
self,
f: F
) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
fn map_init_err<F, E>( self, f: F ) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
Map this factory’s init error to a different error, returning a new service.