Trait actix_service::NewService
source · 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§
Required Methods§
sourcefn new_service(&self) -> Self::Future
fn new_service(&self) -> Self::Future
Create and return a new service value asynchronously.
Provided Methods§
sourcefn 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 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>,
Apply function to specified service and use it as a next service in chain.
sourcefn 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 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>,
Call another service after call to this one has resolved successfully.
sourcefn from_err<E>(self) -> FromErrNewService<Self, E>where
Self: Sized,
E: From<Self::Error>,
fn from_err<E>(self) -> FromErrNewService<Self, E>where
Self: Sized,
E: From<Self::Error>,
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.
sourcefn 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 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>,
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.
sourcefn map<F, R>(self, f: F) -> MapNewService<Self, F, R>where
Self: Sized,
F: Fn(Self::Response) -> R,
fn map<F, R>(self, f: F) -> MapNewService<Self, F, R>where
Self: Sized,
F: Fn(Self::Response) -> R,
Map this service’s output to a different type, returning a new service of the resulting type.
sourcefn map_err<F, E>(self, f: F) -> MapErrNewService<Self, F, E>where
Self: Sized,
F: Fn(Self::Error) -> E,
fn map_err<F, E>(self, f: F) -> MapErrNewService<Self, F, E>where
Self: Sized,
F: Fn(Self::Error) -> E,
Map this service’s error to a different error, returning a new service.
sourcefn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>where
Self: Sized,
F: Fn(Self::InitError) -> E,
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>where
Self: Sized,
F: Fn(Self::InitError) -> E,
Map this service’s init error to a different error, returning a new service.