Skip to main content

BeforeMiddleware

Trait BeforeMiddleware 

Source
pub trait BeforeMiddleware:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn before<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _: &'life1 mut Request,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn catch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _: &'life1 mut Request,
        err: Error,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

BeforeMiddleware are fired before a Handler is called inside of a Middlewares.

BeforeMiddleware are responsible for doing request pre-processing that requires the ability to change control-flow, such as authorization middleware, or for editing the request by modifying the headers.

BeforeMiddleware only have access to the Request, if you need to modify or read a Response, you will need AfterMiddleware. Middleware which wishes to send an early response that is not an error cannot be BeforeMiddleware, but should instead be AroundMiddleware.

Provided Methods§

Source

fn before<'life0, 'life1, 'async_trait>( &'life0 self, _: &'life1 mut Request, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Do whatever work this middleware should do with a Request object.

Source

fn catch<'life0, 'life1, 'async_trait>( &'life0 self, _: &'life1 mut Request, err: Error, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Respond to an error thrown by a previous BeforeMiddleware.

Returning a Ok will cause the request to resume the normal flow at the next BeforeMiddleware, or if this was the last BeforeMiddleware, at the Handler.

Trait Implementations§

Source§

impl BeforeMiddleware for Box<dyn BeforeMiddleware>

Source§

fn before<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Do whatever work this middleware should do with a Request object.
Source§

fn catch<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, err: Error, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Respond to an error thrown by a previous BeforeMiddleware. Read more

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl BeforeMiddleware for Box<dyn BeforeMiddleware>

Source§

fn before<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn catch<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, err: Error, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T> BeforeMiddleware for Arc<T>

Source§

fn before<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn catch<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 mut Request, err: Error, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

Source§

impl<F> BeforeMiddleware for F
where F: Send + Sync + 'static + Fn(&mut Request) -> Result<()>,