titan_core/
handler.rs

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
use std::future::Future;

pub trait Handler<Args>: Send + 'static {
  type Output;
  type Future: Future<Output = Self::Output>;
  fn call(&self, req: Args) -> Self::Future;
}

macro_rules! factory_tuple ({ $($param:ident)* } => {
    impl<Func, Fut, $($param,)*> Handler<($($param,)*)> for Func
    where
        Func: Fn($($param),*) -> Fut + Send + 'static,
        Fut: Future + Send,
    {
        type Output = Fut::Output;
        type Future = Fut;

        #[inline]
        #[allow(non_snake_case)]
        fn call(&self, ($($param,)*): ($($param,)*)) -> Self::Future {
            (self)($($param,)*)
        }
    }
});
//impl<Func, Fut> Handler<((),)> for Func
//where
//  Func: Fn() -> Fut + Send + 'static,
//  Fut: Future + Send,
//{
//  type Future = Fut;
//  type Output = Fut::Output;
//
//  fn call(&self, req: ()) -> Self::Future {
//    let _ = req;
//    self()
//  }
//}

factory_tuple! {}
factory_tuple! { A }
factory_tuple! { A B }
factory_tuple! { A B C }
factory_tuple! { A B C D }
factory_tuple! { A B C D E }
factory_tuple! { A B C D E F }
factory_tuple! { A B C D E F I }
factory_tuple! { A B C D E F I J }
factory_tuple! { A B C D E F I J K }
factory_tuple! { A B C D E F I J K L }