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
use crate::{BoxFuture, Context, Extract, Future, Handler, Response, Result};

macro_rules! peel {
    ($T0:ident, $($T:ident,)*) => (tuple! { $($T,)* })
}

macro_rules! tuple {
    () => (
        #[doc(hidden)]
        impl Extract for ()
        {
            type Error = Response;

            fn extract(_: &mut Context) -> BoxFuture<'_, Result<Self, Self::Error>> {
                Box::pin(async { Ok(()) })
            }
        }

        #[doc(hidden)]
        impl<Func, Fut > Handler<()> for Func
        where
            Func: Fn() -> Fut + Clone + 'static,
            Fut: Future + Send + 'static,
            Fut::Output: Into<Response>,
        {
            type Output = Fut::Output;
            type Future = Fut;

            fn call(&self, _: ()) -> Self::Future {
                (self)()
            }
        }
    );
    ($($T:ident,)+) => (
        #[doc(hidden)]
        impl<$($T),+> Extract for ($($T,)+)
        where
            $($T: Extract + Send,)+
            $($T::Error: Into<Response> + Send + 'static,)+
        {
            type Error = Response;

            fn extract(cx: &mut Context) -> BoxFuture<'_, Result<Self, Self::Error>> {
                Box::pin(async move {
                    Ok((
                        $(
                            $T::extract(cx).await.map_err(Into::<Response>::into)?,
                        )+
                    ))
                })
            }
        }

        #[doc(hidden)]
        impl<Func, $($T,)+ Fut> Handler<($($T,)+)> for Func
        where
            Func: Fn($($T,)+) -> Fut + Clone + 'static,
            Fut: Future + Send + 'static,
            Fut::Output: Into<Response>,
        {
            type Output = Fut::Output;
            type Future = Fut;

            fn call(&self, args: ($($T,)+)) -> Self::Future {
                #[allow(non_snake_case)]
                let ($($T,)+) = args;
                (self)($($T,)+)
            }
        }

        peel! { $($T,)+ }
    )
}

tuple! { A, B, C, D, E, F, G, H, I, J, K, L, }