1use crate::handler::Handler;
2use crate::internal_prelude::*;
3
4pub trait Middleware: Send + Sync {
5 fn handle<'t, 'n, 'a>(
6 &'t self,
7 req: Request,
8 next: &'n dyn Handler,
9 ) -> BoxFuture<'a, Result<Response>>
10 where
11 't: 'a,
12 'n: 'a,
13 Self: 'a;
14
15 fn boxed(self) -> Box<dyn Middleware>
16 where
17 Self: Sized + 'static,
18 {
19 Box::new(self)
20 }
21}
22
23impl Middleware for Box<dyn Middleware> {
24 fn handle<'t, 'n, 'a>(
25 &'t self,
26 req: Request,
27 next: &'n dyn Handler,
28 ) -> BoxFuture<'a, Result<Response>>
29 where
30 't: 'a,
31 'n: 'a,
32 Self: 'a,
33 {
34 Middleware::handle(&**self, req, next)
35 }
36}