pub trait NewService<Request> {
    type Response;
    type Error;
    type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
    type InitError;
    type Future: Future<Item = Self::Service, Error = Self::InitError>;

    fn new_service(&self) -> Self::Future;

    fn apply<T, I, F, Out, Req>(
        self,
        service: I,
        f: F
    ) -> AndThenNewService<Self, ApplyNewService<T, F, Self::Response, Out, Req>>
    where
        Self: Sized,
        T: NewService<Req, InitError = Self::InitError, Error = Self::Error>,
        I: IntoNewService<T, Req>,
        F: Fn(Self::Response, &mut T::Service) -> Out + Clone,
        Out: IntoFuture<Error = Self::Error>
, { ... } fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B>
    where
        Self: Sized,
        F: IntoNewService<B, Self::Response>,
        B: NewService<Self::Response, Error = Self::Error, InitError = Self::InitError>
, { ... } fn from_err<E>(self) -> FromErrNewService<Self, E>
    where
        Self: Sized,
        E: From<Self::Error>
, { ... } fn then<F, B>(self, new_service: F) -> ThenNewService<Self, B>
    where
        Self: Sized,
        F: IntoNewService<B, Result<Self::Response, Self::Error>>,
        B: NewService<Result<Self::Response, Self::Error>, Error = Self::Error, InitError = Self::InitError>
, { ... } fn map<F, R>(self, f: F) -> MapNewService<Self, F, R>
    where
        Self: Sized,
        F: Fn(Self::Response) -> R
, { ... } fn map_err<F, E>(self, f: F) -> MapErrNewService<Self, F, E>
    where
        Self: Sized,
        F: Fn(Self::Error) -> E
, { ... } fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>
    where
        Self: Sized,
        F: Fn(Self::InitError) -> E
, { ... } }
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 servier listener. The listner accepts new TCP streams, obtains a new Service value using the NewService trait, and uses that new Service value to process inbound requests on that new TCP stream.

Request - request handled by the service

Required Associated Types§

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 Service instance.

Required Methods§

Create and return a new service value asynchronously.

Provided Methods§

Apply function to specified service and use it as a next service in chain.

Call another service after call to this one has resolved successfully.

NewService that create service to map this service’s error and new service’s init error to any error implementing From for this services Error`.

Note that this function consumes the receiving new service and returns a wrapped version of it.

Create NewService to chain on a computation for when a call to the service finished, passing the result of the call to the next service B.

Note that this function consumes the receiving future and returns a wrapped version of it.

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 service’s init error to a different error, returning a new service.

Implementors§