Trait Middleware

Source
pub trait Middleware<Ex>: Send + Sync {
    // Required method
    fn handle<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: Context<'life1, Ex>,
    ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Use your custom type as a middleware by implement this trait.

You need async_trait to implement this.

See examples/measurer.rs for a example of process time usage measurer middleware.

Required Methods§

Source

fn handle<'life0, 'life1, 'async_trait>( &'life0 self, ctx: Context<'life1, Ex>, ) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Your middleware handler function, it will be called when request reach this middleware

Implementors§

Source§

impl<Ex> Middleware<Ex> for M<Ex>
where Ex: Send + Sync + 'static,

Source§

impl<Ex> Middleware<Ex> for MethodRouter<Ex>
where Ex: Send + Sync + 'static,

Source§

impl<Ex> Middleware<Ex> for Router<Ex>
where Ex: Send + Sync + 'static,

Source§

impl<Exec, Ex> Middleware<Ex> for Amiya<Exec, Ex>
where Exec: Send + Sync, Ex: Send + Sync + 'static,