Trait highnoon::filter::Filter

source ·
pub trait Filter<S: State> {
    fn apply<'life0, 'life1, 'async_trait>(
        &'life0 self,
        req: Request<S>,
        next: Next<'life1, S>
    ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; }
Expand description

A Filter is a reusable bit of logic which wraps an endpoint to provide pre- and post-processing. Filters can call the Next argument to continue processing, or may return early to stop the chain. Filters can be used for logging, authentication, cookie handling and many other uses.

Filter uses the #[async_trait] attribute hence the signature presented in the docs here has been modified. An example of implementing using the attribute:

struct NoOpFilter;

#[async_trait::async_trait]
impl<S: State> Filter<S> for NoOpFilter
{
    async fn apply(&self, req: Request<S>, next: Next<'_, S>) -> Result<Response> {
        next.next(req).await
    }
}

Required Methods

Implementors