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
//! Apply tuple as args to fns

#[cfg(feature = "tuple_meta")]
/// Tuple to fn meta
pub trait TupleFnMeta<R> {
    type DynFnOnce: ?Sized;
    type DynFnMut: ?Sized;
    type DynFn: ?Sized;
    type FnPtr;
}

/// Apply tuple meta
pub trait ApplyTupleMeta<Tuple> {
    type Output;
    type DynFnOnce: ?Sized;
    type DynFnMut: ?Sized;
    type DynFn: ?Sized;
    type FnPtr;
}

/// Apply tuple as args to FnOnce
pub trait ApplyTupleOnce<Tuple> {
    type Output;

    /// Apply tuple as args to FnOnce
    fn apply_tuple_once(self, args: Tuple) -> Self::Output;
}

/// Apply tuple as args to FnMut
pub trait ApplyTupleMut<Tuple>: ApplyTupleOnce<Tuple> {
    /// Apply tuple as args to FnMut
    fn apply_tuple_mut(&mut self, args: Tuple) -> Self::Output;
}

/// Apply tuple as args to Fn
pub trait ApplyTuple<Tuple>: ApplyTupleMut<Tuple> {
    /// Apply tuple as args to Fn
    fn apply_tuple(&self, args: Tuple) -> Self::Output;
}

include!("./gen/apply_tuple.rs");

#[test]
fn test1() {
    let a = (1, 2, 3);
    fn foo(a: i32, b: i32, c: i32) -> i32 {
        a + b + c
    }
    let r = foo.apply_tuple(a);
    assert_eq!(r, 6)
}

#[test]
fn test2() {
    let a = (1, 2, 3);
    fn foo(a: i32, b: i32, c: i32) -> i32 {
        a + b + c
    }
    let r = foo.apply_tuple_mut(a);
    assert_eq!(r, 6)
}

#[test]
fn test3() {
    let a = (1, 2, 3);
    fn foo(a: i32, b: i32, c: i32) -> i32 {
        a + b + c
    }
    let r = foo.apply_tuple_once(a);
    assert_eq!(r, 6)
}