1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use handler::BoxHandler;

pub trait Middleware: Send + Sync {
    fn call(&self, next: BoxHandler) -> BoxHandler;

    #[inline]
    fn into_box(self) -> BoxMiddleware
    where
        Self: Sized + 'static,
    {
        Box::new(self)
    }
}

impl<TFn> Middleware for TFn
where
    TFn: Send + Sync,
    TFn: Fn(BoxHandler) -> BoxHandler,
{
    #[inline]
    fn call(&self, next: BoxHandler) -> BoxHandler {
        (*self)(next)
    }
}

#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
pub type BoxMiddleware = Box<Middleware>;