actix_service

Trait ServiceExt

source
pub trait ServiceExt<Req>: Service<Req> {
    // Provided methods
    fn map<F, R>(self, f: F) -> Map<Self, F, Req, R>
       where Self: Sized,
             F: FnMut(Self::Response) -> R { ... }
    fn map_err<F, E>(self, f: F) -> MapErr<Self, Req, F, E>
       where Self: Sized,
             F: Fn(Self::Error) -> E { ... }
    fn and_then<I, S1>(self, service: I) -> AndThenService<Self, S1, Req>
       where Self: Sized,
             I: IntoService<S1, Self::Response>,
             S1: Service<Self::Response, Error = Self::Error> { ... }
}
Expand description

An extension trait for Services that provides a variety of convenient adapters.

Provided Methods§

source

fn map<F, R>(self, f: F) -> Map<Self, F, Req, R>
where Self: Sized, F: FnMut(Self::Response) -> R,

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

This function is similar to the Option::map or Iterator::map where it will change the type of the underlying service.

Note that this function consumes the receiving service and returns a wrapped version of it, similar to the existing map methods in the standard library.

source

fn map_err<F, E>(self, f: F) -> MapErr<Self, Req, F, E>
where Self: Sized, F: Fn(Self::Error) -> E,

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

This function is similar to the Result::map_err where it will change the error type of the underlying service. For example, this can be useful to ensure that services have the same error type.

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

source

fn and_then<I, S1>(self, service: I) -> AndThenService<Self, S1, Req>
where Self: Sized, I: IntoService<S1, Self::Response>, S1: Service<Self::Response, Error = Self::Error>,

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

This function can be used to chain two services together and ensure that the second service isn’t called until call to the first service have finished. Result of the call to the first service is used as an input parameter for the second service’s call.

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

Implementors§

source§

impl<S, Req> ServiceExt<Req> for S
where S: Service<Req>,