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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
//! Type operators for tuple types.

// first type of pair

/// A type operator that takes first type of tuple.
pub trait FirstOf {
    type Output;
}

pub type FirstOfOutput<T> = <T as FirstOf>::Output;

impl<A> FirstOf for (A,) {
    type Output = A;
}

impl<A, B> FirstOf for (A, B) {
    type Output = A;
}

impl<A, B, C> FirstOf for (A, B, C) {
    type Output = A;
}

impl<A, B, C, D> FirstOf for (A, B, C, D) {
    type Output = A;
}

impl<A, B, C, D, E> FirstOf for (A, B, C, D, E) {
    type Output = A;
}

// second type of pair

/// A type operator that takes second type of tuple.
pub trait SecondOf {
    type Output;
}

pub type SecondOfOutput<T> = <T as SecondOf>::Output;

impl<A, B> SecondOf for (A, B) {
    type Output = B;
}

impl<A, B, C> SecondOf for (A, B, C) {
    type Output = B;
}

impl<A, B, C, D> SecondOf for (A, B, C, D) {
    type Output = B;
}

impl<A, B, C, D, E> SecondOf for (A, B, C, D, E) {
    type Output = B;
}

// thirt type of pair

/// A type operator that takes third type of tuple.
pub trait ThirdOf {
    type Output;
}

pub type ThirdOfOutput<T> = <T as ThirdOf>::Output;

impl<A, B, C> ThirdOf for (A, B, C) {
    type Output = C;
}

impl<A, B, C, D> ThirdOf for (A, B, C, D) {
    type Output = C;
}

impl<A, B, C, D, E> ThirdOf for (A, B, C, D, E) {
    type Output = C;
}

// left associate

pub trait LeftAssociate {
    type Output;
}

pub type LeftAssociateOutput<T> = <T as LeftAssociate>::Output;

impl<A, B, C> LeftAssociate for (A, (B, C)) {
    type Output = ((A, B), C);
}

// Right associate

pub trait RightAssociate {
    type Output;
}

pub type RightAssociateOutput<T> = <T as RightAssociate>::Output;

impl<A, B, C> RightAssociate for ((A, B), C) {
    type Output = (A, (B, C));
}