pub trait ServiceFactory<St, Req> {
type Res;
type Error;
type Service: Service<St, Req, Res = Self::Res, Error = Self::Error>;
type InitError;
// Required method
async fn create(&self, st: &St) -> Result<Self::Service, Self::InitError>;
// Provided methods
async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>
where Self: 'static,
St: 'static,
Req: 'static { ... }
fn map<F, Res>(
self,
f: F,
) -> ServiceChainFactory<MapFactory<F, Self, Res>, St, Req>
where Self: Sized,
F: Fn(Self::Res) -> Res + Clone { ... }
fn map_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapErrFactory<F, Self, E>, St, Req>
where Self: Sized,
F: Fn(Self::Error) -> E + Clone { ... }
fn map_init_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapInitErr<F, Self, E>, St, Req>
where Self: Sized,
F: Fn(Self::InitError) -> E + Clone { ... }
fn and_then<U, F>(
self,
f: F,
) -> ServiceChainFactory<AndThenFactory<Self, U>, St, Req>
where Self: Sized,
U: ServiceFactory<St, Self::Res, Error = Self::Error, InitError = Self::InitError>,
F: IntoServiceFactory<U, St, Self::Res> { ... }
fn boxed(
self,
) -> BoxServiceFactory<St, Req, Self::Res, Self::Error, Self::InitError>
where St: 'static,
Req: 'static,
Self: Sized + 'static { ... }
}Expand description
A factory for asynchronously creating Service values.
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.
St is the state type shared by the factory and its services.
Simple factories can often use fn_factory to reduce boilerplate.
Required Associated Types§
Required Methods§
Provided Methods§
Sourceasync fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
Creates a service and wraps it with its state in a Pipeline.
Sourcefn map<F, Res>(
self,
f: F,
) -> ServiceChainFactory<MapFactory<F, Self, Res>, St, Req>
fn map<F, Res>( self, f: F, ) -> ServiceChainFactory<MapFactory<F, Self, Res>, St, Req>
Returns a factory whose services map responses to a different type.
Sourcefn map_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapErrFactory<F, Self, E>, St, Req>
fn map_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapErrFactory<F, Self, E>, St, Req>
Returns a factory whose services map errors to a different type.
Sourcefn map_init_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapInitErr<F, Self, E>, St, Req>
fn map_init_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapInitErr<F, Self, E>, St, Req>
Maps this factory’s initialization error to a different error, returning a new service factory.
Sourcefn and_then<U, F>(
self,
f: F,
) -> ServiceChainFactory<AndThenFactory<Self, U>, St, Req>where
Self: Sized,
U: ServiceFactory<St, Self::Res, Error = Self::Error, InitError = Self::InitError>,
F: IntoServiceFactory<U, St, Self::Res>,
fn and_then<U, F>(
self,
f: F,
) -> ServiceChainFactory<AndThenFactory<Self, U>, St, Req>where
Self: Sized,
U: ServiceFactory<St, Self::Res, Error = Self::Error, InitError = Self::InitError>,
F: IntoServiceFactory<U, St, Self::Res>,
Chains another factory after this factory’s services.
Each response from the first service becomes a request to the second service. The second service is not called when the first returns an error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".