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
use std::future::Future;
use futures_util::future::BoxFuture;
use crate::request::Ctx;
use crate::request::ctx::extract::ExtractFromRequestCtx;
use crate::response::Response;

pub trait HandlerCtxArgument<A>: Send + Sync + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>>;
}

impl<F, Fut> HandlerCtxArgument<()> for F where
    F: Fn() -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        Box::pin(self())
    }
}

impl<A0, F, Fut> HandlerCtxArgument<(A0,)> for F where
    A0: ExtractFromRequestCtx + Send + Sync,
    F: Fn(A0) -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        let value: A0 = ExtractFromRequestCtx::extract(&ctx);
        Box::pin(self(value))
    }
}

impl<A0, A1, F, Fut> HandlerCtxArgument<(A0, A1)> for F where
    A0: ExtractFromRequestCtx + Send + Sync,
    A1: ExtractFromRequestCtx + Send + Sync,
    F: Fn(A0, A1) -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        let value0: A0 = ExtractFromRequestCtx::extract(&ctx);
        let value1: A1 = ExtractFromRequestCtx::extract(&ctx);
        Box::pin(self(value0, value1))
    }
}

impl<A0, A1, A2, F, Fut> HandlerCtxArgument<(A0, A1, A2)> for F where
    A0: ExtractFromRequestCtx + Send + Sync,
    A1: ExtractFromRequestCtx + Send + Sync,
    A2: ExtractFromRequestCtx + Send + Sync,
    F: Fn(A0, A1, A2) -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        let value0: A0 = ExtractFromRequestCtx::extract(&ctx);
        let value1: A1 = ExtractFromRequestCtx::extract(&ctx);
        let value2: A2 = ExtractFromRequestCtx::extract(&ctx);
        Box::pin(self(value0, value1, value2))
    }
}

impl<A0, A1, A2, A3, F, Fut> HandlerCtxArgument<(A0, A1, A2, A3)> for F where
    A0: ExtractFromRequestCtx + Send + Sync,
    A1: ExtractFromRequestCtx + Send + Sync,
    A2: ExtractFromRequestCtx + Send + Sync,
    A3: ExtractFromRequestCtx + Send + Sync,
    F: Fn(A0, A1, A2, A3) -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        let value0: A0 = ExtractFromRequestCtx::extract(&ctx);
        let value1: A1 = ExtractFromRequestCtx::extract(&ctx);
        let value2: A2 = ExtractFromRequestCtx::extract(&ctx);
        let value3: A3 = ExtractFromRequestCtx::extract(&ctx);
        Box::pin(self(value0, value1, value2, value3))
    }
}

impl<A0, A1, A2, A3, A4, F, Fut> HandlerCtxArgument<(A0, A1, A2, A3, A4)> for F where
    A0: ExtractFromRequestCtx + Send + Sync,
    A1: ExtractFromRequestCtx + Send + Sync,
    A2: ExtractFromRequestCtx + Send + Sync,
    A3: ExtractFromRequestCtx + Send + Sync,
    A4: ExtractFromRequestCtx + Send + Sync,
    F: Fn(A0, A1, A2, A3, A4) -> Fut + Sync + Send + Clone + 'static,
    Fut: Future<Output = crate::path::Result<Response>> + Send + 'static {
    fn call(&self, ctx: Ctx) -> BoxFuture<'static, crate::path::Result<Response>> {
        let value0: A0 = ExtractFromRequestCtx::extract(&ctx);
        let value1: A1 = ExtractFromRequestCtx::extract(&ctx);
        let value2: A2 = ExtractFromRequestCtx::extract(&ctx);
        let value3: A3 = ExtractFromRequestCtx::extract(&ctx);
        let value4: A4 = ExtractFromRequestCtx::extract(&ctx);
        Box::pin(self(value0, value1, value2, value3, value4))
    }
}