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
macro_rules! tuple_impls {
    () => {
        tuple_impls!(@impl);
    };
    ($T:ident $( $U:ident )*) => {
        tuple_impls!($( $U )*);
        tuple_impls!(@impl $T $( $U )*);
    };
    // "Private" internal implementation
    (@impl $( $T:ident )*) => {
        #[async_trait]
        impl<$($T,)*> FromRequest for ($($T,)*)
        where
            $($T: FromRequest + Send + 'static,)*
            $($T::Error: IntoResponse + Send,)*
        {
            type Error = Error;

            #[allow(unused, unused_mut)]
            async fn extract(req: &mut Request) -> Result<($($T,)*), Self::Error> {
                Ok(($($T::extract(req).await.map_err(IntoResponse::into_error)?,)*))
            }
        }

        #[async_trait]
        impl<$($T,)* Fun, Fut, Out> FnExt<($($T,)*)> for Fun
        where
            $($T: FromRequest + Send + 'static,)*
            $($T::Error: IntoResponse + Send,)*
            Fun: Fn($($T,)*) -> Fut + Clone + Send + Sync + 'static,
            Fut: Future<Output = Result<Out>> + Send,
            Out: Send + Sync + 'static,
            // Out: IntoResponse + Send + Sync + 'static,
        {
            type Output =  Fut::Output;
            // type Output =  Result<Response>;

            #[allow(unused, unused_mut)]
            async fn call(&self, mut req: Request) -> Self::Output {
                (self)($($T::extract(&mut req).await.map_err(IntoResponse::into_error)?,)*)
                    .await
                    // .await.map(IntoResponse::into_response)
            }
        }
    };
}