Trait ServiceFactory

Source
pub trait ServiceFactory {
    type Request;
    type Response;
    type Error;
    type Config;
    type Service: Service<Request = Self::Request, Response = Self::Response, Error = Self::Error>;
    type InitError;
    type Future: Future<Output = Result<Self::Service, Self::InitError>>;

    // Required method
    fn new_service(&self, cfg: Self::Config) -> Self::Future;

    // Provided methods
    fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R>
       where Self: Sized,
             F: FnMut(Self::Response) -> R + Clone { ... }
    fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E>
       where Self: Sized,
             F: Fn(Self::Error) -> E + Clone { ... }
    fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>
       where Self: Sized,
             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.

Required Associated Types§

Source

type Request

Requests handled by the service.

Source

type Response

Responses given by the service

Source

type Error

Errors produced by the service

Source

type Config

Service factory configuration

Source

type Service: Service<Request = Self::Request, Response = Self::Response, Error = Self::Error>

The Service value created by this factory

Source

type InitError

Errors produced while building a service.

Source

type Future: Future<Output = Result<Self::Service, Self::InitError>>

The future of the Service instance.

Required Methods§

Source

fn new_service(&self, cfg: Self::Config) -> Self::Future

Create and return a new service value asynchronously.

Provided Methods§

Source

fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R>
where Self: Sized, F: FnMut(Self::Response) -> R + Clone,

Map this service’s output to a different type, returning a new service of the resulting type.

Source

fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E>
where Self: Sized, F: Fn(Self::Error) -> E + Clone,

Map this service’s error to a different error, returning a new service.

Source

fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, 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.

Implementations on Foreign Types§

Source§

impl<S> ServiceFactory for Rc<S>
where S: ServiceFactory,

Source§

impl<S> ServiceFactory for Arc<S>
where S: ServiceFactory,

Implementors§

Source§

impl<A, C> ServiceFactory for UnitConfig<A, C>
where A: ServiceFactory<Config = ()>,

Source§

impl<A, F, C> ServiceFactory for MapConfig<A, F, C>
where A: ServiceFactory, F: Fn(C) -> A::Config,

Source§

impl<A, F, E> ServiceFactory for MapErrServiceFactory<A, F, E>
where A: ServiceFactory, F: Fn(A::Error) -> E + Clone,

Source§

impl<A, F, E> ServiceFactory for MapInitErr<A, F, E>
where A: ServiceFactory, F: Fn(A::InitError) -> E + Clone,

Source§

impl<A, F, Res> ServiceFactory for MapServiceFactory<A, F, Res>
where A: ServiceFactory, F: FnMut(A::Response) -> Res + Clone,

Source§

type Request = <A as ServiceFactory>::Request

Source§

type Response = Res

Source§

type Error = <A as ServiceFactory>::Error

Source§

type Config = <A as ServiceFactory>::Config

Source§

type Service = Map<<A as ServiceFactory>::Service, F, Res>

Source§

type InitError = <A as ServiceFactory>::InitError

Source§

type Future = MapServiceFuture<A, F, Res>

Source§

impl<C, Req, Res, Err, InitErr> ServiceFactory for BoxServiceFactory<C, Req, Res, Err, InitErr>
where Req: 'static, Res: 'static, Err: 'static, InitErr: 'static,

Source§

type Request = Req

Source§

type Response = Res

Source§

type Error = Err

Source§

type InitError = InitErr

Source§

type Config = C

Source§

type Service = Box<dyn Service<Request = Req, Response = Res, Error = Err, Future = Pin<Box<dyn Future<Output = Result<Res, Err>>>>>>

Source§

type Future = Pin<Box<dyn Future<Output = Result<<BoxServiceFactory<C, Req, Res, Err, InitErr> as ServiceFactory>::Service, InitErr>>>>

Source§

impl<F, C, S, R, E> ServiceFactory for FnServiceNoConfig<F, C, S, R, E>
where F: Fn() -> R, R: Future<Output = Result<S, E>>, S: Service,

Source§

impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnServiceConfig<F, Fut, Cfg, Srv, Err>
where F: Fn(Cfg) -> Fut, Fut: Future<Output = Result<Srv, Err>>, Srv: Service,

Source§

type Request = <Srv as Service>::Request

Source§

type Response = <Srv as Service>::Response

Source§

type Error = <Srv as Service>::Error

Source§

type Config = Cfg

Source§

type Service = Srv

Source§

type InitError = Err

Source§

type Future = Fut

Source§

impl<F, Fut, Req, Res, Err, Cfg> ServiceFactory for FnServiceFactory<F, Fut, Req, Res, Err, Cfg>
where F: FnMut(Req) -> Fut + Clone, Fut: Future<Output = Result<Res, Err>>,

Source§

type Request = Req

Source§

type Response = Res

Source§

type Error = Err

Source§

type Config = Cfg

Source§

type Service = FnService<F, Fut, Req, Res, Err>

Source§

type InitError = ()

Source§

type Future = Ready<Result<<FnServiceFactory<F, Fut, Req, Res, Err, Cfg> as ServiceFactory>::Service, <FnServiceFactory<F, Fut, Req, Res, Err, Cfg> as ServiceFactory>::InitError>>

Source§

impl<T, F, R, In, Out, Err> ServiceFactory for ApplyServiceFactory<T, F, R, In, Out, Err>
where T: ServiceFactory<Error = Err>, F: FnMut(In, &mut T::Service) -> R + Clone, R: Future<Output = Result<Out, Err>>,

Source§

type Request = In

Source§

type Response = Out

Source§

type Error = Err

Source§

type Config = <T as ServiceFactory>::Config

Source§

type Service = Apply<<T as ServiceFactory>::Service, F, R, In, Out, Err>

Source§

type InitError = <T as ServiceFactory>::InitError

Source§

type Future = ApplyServiceFactoryResponse<T, F, R, In, Out, Err>

Source§

impl<T, S> ServiceFactory for ApplyTransform<T, S>
where S: ServiceFactory, T: Transform<S::Service, InitError = S::InitError>,

Source§

impl<T: ServiceFactory> ServiceFactory for PipelineFactory<T>