pub trait ServiceFactory<Req, Cfg = ()> {
type Response;
type Error;
type Service: Service<Req, Response = Self::Response, Error = Self::Error>;
type InitError;
// Required method
async fn create(&self, cfg: Cfg) -> Result<Self::Service, Self::InitError>;
// Provided methods
async fn pipeline(
&self,
cfg: Cfg,
) -> Result<Pipeline<Self::Service>, Self::InitError>
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 { ... }
fn boxed(
self,
) -> BoxServiceFactory<Cfg, Req, Self::Response, Self::Error, Self::InitError>
where Cfg: 'static,
Req: 'static,
Self: 'static + Sized { ... }
}Expand description
A factory for creating Services.
This is useful when new Services must be produced dynamically. For example,
a TCP server listener accepts new connections, constructs a new Service for
each connection using the ServiceFactory trait, and uses that service to
handle inbound requests.
Config represents the configuration type for the service factory.
Simple factories can often use fn_factory or fn_factory_with_config
to reduce boilerplate.
Required Associated Types§
Required Methods§
Provided Methods§
Sourceasync fn pipeline(
&self,
cfg: Cfg,
) -> Result<Pipeline<Self::Service>, Self::InitError>where
Self: Sized,
async fn pipeline(
&self,
cfg: Cfg,
) -> Result<Pipeline<Self::Service>, Self::InitError>where
Self: Sized,
Asynchronously creates a new service and wraps it in 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>
Returns a new service that maps this service’s output to a different 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>
Transforms this service’s error into another error, producing 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>
Maps this factory’s initialization error to a different error, returning a new service factory.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.