Trait ajars_actix_web::actix_web::dev::Transform [−]
pub trait Transform<S, Req> { type Response; type Error; type Transform: Service<Req>; type InitError; type Future: Future; fn new_transform(&self, service: S) -> Self::Future; }
Expand description
Defines the interface of a service factory that wraps inner service during construction.
Transformers wrap an inner service and runs during inbound and/or outbound processing in the service lifecycle. It may modify request and/or response.
For example, a timeout service wrapper:
pub struct Timeout<S> { service: S, timeout: Duration, } impl<S: Service<Req>, Req> Service<Req> for Timeout<S> { type Response = S::Response; type Error = TimeoutError<S::Error>; type Future = TimeoutServiceResponse<S>; actix_service::forward_ready!(service); fn call(&self, req: S::Request) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(req), sleep: Sleep::new(clock::now() + self.timeout), } } }
This wrapper service is decoupled from the underlying service implementation and could be applied to any service.
The Transform
trait defines the interface of a service wrapper. Transform
is often
implemented for middleware, defining how to construct a middleware Service. A Service that is
constructed by the factory takes the Service that follows it during execution as a parameter,
assuming ownership of the next Service.
A transform for the Timeout
middleware could look like this:
pub struct TimeoutTransform { timeout: Duration, } impl<S: Service<Req>, Req> Transform<S, Req> for TimeoutTransform { type Response = S::Response; type Error = TimeoutError<S::Error>; type InitError = S::Error; type Transform = Timeout<S>; type Future = Ready<Result<Self::Transform, Self::InitError>>; fn new_transform(&self, service: S) -> Self::Future { ready(Ok(Timeout { service, timeout: self.timeout, })) } }
Associated Types
type Response
type Response
Responses produced by the service.
type Error
type Error
Errors produced by the service.
type InitError
type InitError
Errors produced while building a transform service.
Required methods
fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Implementations on Foreign Types
pub fn new_transform(&self, service: S) -> <T as Transform<S, Req>>::Future
pub fn new_transform(&self, service: S) -> <T as Transform<S, Req>>::Future
Implementors
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
<S as Service<ServiceRequest>>::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B> where
B: 'static,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
<S as Service<ServiceRequest>>::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for Logger where
B: MessageBody,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
impl<S, B> Transform<S, ServiceRequest> for NormalizePath where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
<S as Service<ServiceRequest>>::Future: 'static,
impl<S, T, Req> Transform<S, Req> for Compat<T> where
T: Transform<S, Req>,
S: Service<Req>,
<T as Transform<S, Req>>::Future: 'static,
<T as Transform<S, Req>>::Response: MapServiceResponseBody,
<T as Transform<S, Req>>::Error: Into<Error>,
impl<S, T, Req> Transform<S, Req> for Condition<T> where
T: Transform<S, Req, Response = <S as Service<Req>>::Response, Error = <S as Service<Req>>::Error>,
S: Service<Req> + 'static,
<T as Transform<S, Req>>::Future: 'static,
<T as Transform<S, Req>>::InitError: 'static,
<T as Transform<S, Req>>::Transform: 'static,