Middleware

Trait Middleware 

Source
pub trait Middleware<Req: Request, Resp: Response>:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: Req,
        next: Next<'life1, Req, Resp>,
    ) -> Pin<Box<dyn Future<Output = HttpResult<Resp>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn name(&self) -> &str { ... }
}
Expand description

Middleware that wraps around the remaining middleware chain.

Required Methods§

Source

fn handle<'life0, 'life1, 'async_trait>( &'life0 self, request: Req, next: Next<'life1, Req, Resp>, ) -> Pin<Box<dyn Future<Output = HttpResult<Resp>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously handle the request, and return a response.

Provided Methods§

Source

fn name(&self) -> &str

Set the middleware’s name. By default it uses the type signature.

Implementors§

Source§

impl<Req, Resp, F> Middleware<Req, Resp> for F
where Req: Request, Resp: Response, F: Send + Sync + 'static + for<'a> Fn(Req, Next<'a, Req, Resp>) -> Pin<Box<dyn Future<Output = HttpResult<Resp>> + Send + 'a>>,