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
//! Combine tuples

/// Add Item on Left
pub trait CombinLeft<T> {
    type Out;

    /// Add Item on Left
    fn left(self, target: T) -> Self::Out;
}

/// Add Item on Right
pub trait CombinRight<T> {
    type Out;

    /// Add Item on Right
    fn push(self, target: T) -> Self::Out;
}

/// Concat Tuples  
/// `(a, b).concat((c, d)) -> (a, b, c, d)`
pub trait CombinConcat<T> {
    type Out;

    /// Concat Tuples  
    /// `(a, b).concat((c, d)) -> (a, b, c, d)`
    fn concat(self, target: T) -> Self::Out;
}

impl<T> CombinLeft<T> for () {
    type Out = (T,);

    fn left(self, target: T) -> Self::Out {
        (target,)
    }
}

impl<T> CombinRight<T> for () {
    type Out = (T,);

    fn push(self, target: T) -> Self::Out {
        (target,)
    }
}

impl<T, T0> CombinLeft<T> for (T0,) {
    type Out = (T, T0);

    fn left(self, target: T) -> Self::Out {
        (target, self.0)
    }
}

impl<T, T0> CombinRight<T> for (T0,) {
    type Out = (T0, T);

    fn push(self, target: T) -> Self::Out {
        (self.0, target)
    }
}

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

#[test]
fn test() {
    let a = (1, 2).push(3);
    assert_eq!(a, (1, 2, 3));
    let b = (2, 1).left(3);
    assert_eq!(b, (3, 2, 1));
    let c = (1, 2, 3).concat((4, 5, 6));
    assert_eq!(c, (1, 2, 3, 4, 5, 6))
}