pub trait ServiceFactory<Req, Cfg = ()> {
type Response;
type Error;
type Service: Service<Req>;
type InitError;
type Future: Future;
fn new_service(&self, cfg: Cfg) -> Self::Future;
fn map<F, Res>(self, f: F) -> MapServiceFactory<Self, F, Req, Res, Cfg>
where
F: FnMut(Self::Response) -> Res + Clone,
{ ... }
fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, Req, Cfg, F, E>
where
F: Fn(Self::Error) -> E + Clone,
{ ... }
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, Req, Cfg, F, E>
where
F: Fn(Self::InitError) -> E + Clone,
{ ... }
}
Expand description
Creates new Service
values.
Acts as a service factory. This is useful for cases where new Service
values must be produced. One case is a TCP server listener. The listener
accepts new TCP streams, obtains a new Service
value using the
ServiceFactory
trait, and uses that new Service
value to process inbound
requests on that new TCP stream.
Config
is a service factory configuration type.
Responses given by the service
Errors produced by the service
The Service
value created by this factory
Errors produced while building a service.
The future of the ServiceFactory
instance.
Create and return a new service value asynchronously.
Map this service’s output to a different type, returning a new service
of the resulting type.
Map this service’s error to a different error, returning a new service.
Map this factory’s init error to a different error, returning a new service.
impl<A, R, F, C, C2> ServiceFactory<R, C> for MapConfig<A, R, F, C, C2> where
A: ServiceFactory<R, C2>,
F: Fn(C) -> C2,
impl<C, Req, Res, Err, InitErr> ServiceFactory<Req, C> for BoxServiceFactory<C, Req, Res, Err, InitErr> where
Req: 'static,
Res: 'static,
Err: 'static,
InitErr: 'static,
impl<F, C, S, R, Req, E> ServiceFactory<Req, C> for FnServiceNoConfig<F, C, S, R, Req, E> where
F: Fn() -> R,
R: Future<Output = Result<S, E>>,
S: Service<Req>,
impl<F, Fut, Cfg, Srv, Req, Err> ServiceFactory<Req, Cfg> for FnServiceConfig<F, Fut, Cfg, Srv, Req, Err> where
F: Fn(Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>,
Srv: Service<Req>,
impl<F, Fut, Req, Res, Err, Cfg, FShut> ServiceFactory<Req, Cfg> for FnServiceFactory<F, Fut, Req, Res, Err, Cfg, FShut> where
F: Fn(Req) -> Fut + Clone,
FShut: FnOnce() + Clone,
Fut: Future<Output = Result<Res, Err>>,
impl<T, Req, Cfg, F, R, In, Out, Err> ServiceFactory<In, Cfg> for ApplyServiceFactory<T, Req, Cfg, F, R, In, Out, Err> where
T: ServiceFactory<Req, Cfg, Error = Err>,
F: Fn(In, &<T as ServiceFactory<Req, Cfg>>::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
impl<V1, V1C, V2, V3, V4, V1R, V2R, V3R, V4R> ServiceFactory<Variant4<V1R, V2R, V3R, V4R>, V1C> for VariantFactory4<V1, V1C, V2, V3, V4, V1R, V2R, V3R, V4R> where
V1: ServiceFactory<V1R, V1C>,
V1C: Clone,
V2: ServiceFactory<V2R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V3: ServiceFactory<V3R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V4: ServiceFactory<V4R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
impl<V1, V1C, V2, V3, V4, V5, V1R, V2R, V3R, V4R, V5R> ServiceFactory<Variant5<V1R, V2R, V3R, V4R, V5R>, V1C> for VariantFactory5<V1, V1C, V2, V3, V4, V5, V1R, V2R, V3R, V4R, V5R> where
V1: ServiceFactory<V1R, V1C>,
V1C: Clone,
V2: ServiceFactory<V2R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V3: ServiceFactory<V3R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V4: ServiceFactory<V4R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V5: ServiceFactory<V5R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
impl<V1, V1C, V2, V3, V4, V5, V6, V1R, V2R, V3R, V4R, V5R, V6R> ServiceFactory<Variant6<V1R, V2R, V3R, V4R, V5R, V6R>, V1C> for VariantFactory6<V1, V1C, V2, V3, V4, V5, V6, V1R, V2R, V3R, V4R, V5R, V6R> where
V1: ServiceFactory<V1R, V1C>,
V1C: Clone,
V2: ServiceFactory<V2R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V3: ServiceFactory<V3R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V4: ServiceFactory<V4R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V5: ServiceFactory<V5R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V6: ServiceFactory<V6R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
impl<V1, V1C, V2, V3, V4, V5, V6, V7, V1R, V2R, V3R, V4R, V5R, V6R, V7R> ServiceFactory<Variant7<V1R, V2R, V3R, V4R, V5R, V6R, V7R>, V1C> for VariantFactory7<V1, V1C, V2, V3, V4, V5, V6, V7, V1R, V2R, V3R, V4R, V5R, V6R, V7R> where
V1: ServiceFactory<V1R, V1C>,
V1C: Clone,
V2: ServiceFactory<V2R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V3: ServiceFactory<V3R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V4: ServiceFactory<V4R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V5: ServiceFactory<V5R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V6: ServiceFactory<V6R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V7: ServiceFactory<V7R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
impl<V1, V1C, V2, V3, V4, V5, V6, V7, V8, V1R, V2R, V3R, V4R, V5R, V6R, V7R, V8R> ServiceFactory<Variant8<V1R, V2R, V3R, V4R, V5R, V6R, V7R, V8R>, V1C> for VariantFactory8<V1, V1C, V2, V3, V4, V5, V6, V7, V8, V1R, V2R, V3R, V4R, V5R, V6R, V7R, V8R> where
V1: ServiceFactory<V1R, V1C>,
V1C: Clone,
V2: ServiceFactory<V2R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V3: ServiceFactory<V3R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V4: ServiceFactory<V4R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V5: ServiceFactory<V5R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V6: ServiceFactory<V6R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V7: ServiceFactory<V7R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
V8: ServiceFactory<V8R, V1C, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,