Skip to main content

MiddlewareContract

Trait MiddlewareContract 

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

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

A stage in the request pipeline.

Required Methods§

Source

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

Handle the request, optionally calling next.

Returning without calling next.run(..) short-circuits the pipeline — the handler and every later middleware are skipped. That is how authentication, rate limiting and CORS preflight all work.

Provided Methods§

Source

fn name(&self) -> &'static str

A label for diagnostics and route:list.

Defaults to the type’s short name. This is a label, not an identifier: nothing looks middleware up by it, so two stages sharing one is untidy rather than broken.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Middleware for ConfirmPassword

Source§

fn handle<'life0, 'async_trait>( &'life0 self, request: Request, next: Next, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where 'life0: 'async_trait, ConfirmPassword: 'async_trait,

Source§

fn name(&self) -> &'static str

Source§

impl Middleware for RequireAbility

Source§

fn handle<'life0, 'async_trait>( &'life0 self, request: Request, next: Next, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where 'life0: 'async_trait, RequireAbility: 'async_trait,

Source§

fn name(&self) -> &'static str

Source§

impl<U> Middleware for Authenticate<U>
where U: Authenticatable,

Source§

fn handle<'life0, 'async_trait>( &'life0 self, request: Request, next: Next, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where 'life0: 'async_trait, Authenticate<U>: 'async_trait,

Source§

fn name(&self) -> &'static str

Source§

impl<U> Middleware for RedirectIfAuthenticated<U>
where U: Authenticatable,

Source§

fn handle<'life0, 'async_trait>( &'life0 self, request: Request, next: Next, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where 'life0: 'async_trait, RedirectIfAuthenticated<U>: 'async_trait,

Source§

fn name(&self) -> &'static str

Implementors§