tupletools/
fst.rs

1#[inline]
2pub fn fst<T: Fst>(t: T) -> T::Ret {
3    t.fst()
4}
5
6pub trait Fst {
7    type Ret;
8    fn fst(self) -> Self::Ret;
9}
10
11pub trait FstTest {
12    type Ret;
13    fn fst(self) -> Self::Ret;
14}
15
16macro_rules! impl_fst {
17    (
18        $( $t:tt ),+ ;$r:ty
19    ) => {
20        impl < $($t),+ > Fst for ($($t),+) {
21            type Ret = $r;
22            fn fst(self) -> Self::Ret {
23                self.0
24            }
25        }
26
27        impl <'a, $($t),+ > Fst for &'a ($($t),+) {
28            type Ret = &'a $r;
29            fn fst(self) -> Self::Ret {
30                &self.0
31            }
32        }
33    };
34}
35
36impl<T> Fst for (T,) {
37    type Ret = T;
38
39    fn fst(self) -> Self::Ret {
40        self.0
41    }
42}
43
44impl<'a, T> Fst for &'a (T,) {
45    type Ret = &'a T;
46
47    fn fst(self) -> Self::Ret {
48        &self.0
49    }
50}
51
52impl_fst!(T0,T1;T0);
53impl_fst!(T0,T1, T2;T0);
54impl_fst!(T0,T1, T2 , T3;T0);
55impl_fst!(T0,T1, T2, T3, T4;T0);
56impl_fst!(T0,T1, T2, T3, T4, T5;T0);
57impl_fst!(T0,T1, T2, T3, T4, T5, T6;T0);
58impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7;T0);
59impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8;T0);
60impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9;T0);
61impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10;T0);
62impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11;T0);
63impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12;T0);
64impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13;T0);
65impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14;T0);
66impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15;T0);
67impl_fst!(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16;T0);