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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#[macro_export]
macro_rules! middleware {
(|$req:tt, mut $res:ident| <$data:path> $($b:tt)+) => { _middleware_inner!($req, $res, mut $res, <$data> $($b)+) };
(|$req:tt, $res:ident| <$data:path> $($b:tt)+) => { _middleware_inner!($req, $res, $res, <$data> $($b)+) };
(|$req:tt| <$data:path> $($b:tt)+) => { middleware!(|$req, _res| <$data> $($b)+) };
(|$req:tt, mut $res:ident| $($b:tt)+) => { _middleware_inner!($req, $res, mut $res, $($b)+) };
(|$req:tt, $res:ident| $($b:tt)+) => { _middleware_inner!($req, $res, $res, $($b)+) };
(|$req:tt| $($b:tt)+) => { middleware!(|$req, _res| $($b)+) };
($($b:tt)+) => { middleware!(|_, _res| $($b)+) };
}
#[doc(hidden)]
#[macro_export]
macro_rules! _middleware_inner {
($req:tt, $res:ident, $res_binding:pat, <$data:path> $($b:tt)+) => {{
use $crate::{MiddlewareResult,Responder, Response, Request};
#[inline(always)]
fn restrict<'mw, R: Responder<$data>>(r: R, res: Response<'mw, $data>)
-> MiddlewareResult<'mw, $data> {
res.send(r)
}
#[inline(always)]
fn restrict_closure<F>(f: F) -> F
where F: for<'r, 'mw, 'conn>
Fn(&'r mut Request<'mw, 'conn, $data>, Response<'mw, $data>)
-> MiddlewareResult<'mw, $data> + Send + Sync { f }
restrict_closure(move |as_pat!($req), $res_binding| {
restrict(as_block!({$($b)+}), $res)
})
}};
($req:tt, $res:ident, $res_binding:pat, $($b:tt)+) => {{
use $crate::{MiddlewareResult,Responder, Response, Request};
#[inline(always)]
fn restrict<'mw, D, R: Responder<D>>(r: R, res: Response<'mw, D>)
-> MiddlewareResult<'mw, D> {
res.send(r)
}
#[inline(always)]
fn restrict_closure<F, D>(f: F) -> F
where F: for<'r, 'mw, 'conn>
Fn(&'r mut Request<'mw, 'conn, D>, Response<'mw, D>)
-> MiddlewareResult<'mw, D> + Send + Sync { f }
restrict_closure(move |as_pat!($req), $res_binding| {
restrict(as_block!({$($b)+}), $res)
})
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! as_block { ($b:block) => ( $b ) }
#[doc(hidden)]
#[macro_export]
macro_rules! as_pat { ($p:pat) => ( $p ) }