Trait ntex_service::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;
fn create(&self, cfg: Cfg) -> Self::Future<'_>;
fn map<F, Res>(self, f: F) -> MapFactory<Self, F, Req, Res, Cfg>
where
Self: Sized,
F: Fn(Self::Response) -> Res + Clone,
{ ... }
fn map_err<F, E>(self, f: F) -> MapErrFactory<Self, Req, Cfg, F, E>
where
Self: Sized,
F: Fn(Self::Error) -> E + Clone,
{ ... }
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, Req, Cfg, F, E>
where
Self: Sized,
F: Fn(Self::InitError) -> E + Clone,
{ ... }
}Expand description
Factory for creating Services.
This is useful for cases where new Services 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 map<F, Res>(self, f: F) -> MapFactory<Self, F, Req, Res, Cfg>where
Self: Sized,
F: Fn(Self::Response) -> Res + Clone,
fn map<F, Res>(self, f: F) -> MapFactory<Self, F, Req, Res, Cfg>where
Self: Sized,
F: Fn(Self::Response) -> Res + Clone,
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) -> MapErrFactory<Self, Req, Cfg, F, E>where
Self: Sized,
F: Fn(Self::Error) -> E + Clone,
fn map_err<F, E>(self, f: F) -> MapErrFactory<Self, Req, Cfg, F, E>where
Self: Sized,
F: Fn(Self::Error) -> E + Clone,
Map this service’s error to a different error, returning a new service.
sourcefn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, Req, Cfg, F, E>where
Self: Sized,
F: Fn(Self::InitError) -> E + Clone,
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, Req, Cfg, F, E>where
Self: Sized,
F: Fn(Self::InitError) -> E + Clone,
Map this factory’s init error to a different error, returning a new service.