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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! As X

use core::ops::{Deref, DerefMut};

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

/// AsRef for Tuple
pub trait TupleAsRef<'a> {
    type OutTuple: 'a;

    /// AsRef for Tuple
    fn as_ref(&'a self) -> Self::OutTuple;
}

impl<'a, T: 'a> TupleAsRef<'a> for (T,) {
    type OutTuple = (&'a T,);

    fn as_ref(&'a self) -> Self::OutTuple {
        (&self.0,)
    }
}

/// AsMut for Tuple
pub trait TupleAsMut<'a> {
    type OutTuple: 'a;

    /// AsMut for Tuple
    fn as_mut(&'a mut self) -> Self::OutTuple;
}

impl<'a, T: 'a> TupleAsMut<'a> for (T,) {
    type OutTuple = (&'a mut T,);

    fn as_mut(&'a mut self) -> Self::OutTuple {
        (&mut self.0,)
    }
}

/// Mapping item to `Option` for Tuple
pub trait TupleAsOption {
    type OutTuple;

    /// Mapping item to `Option::Some` for Tuple
    fn as_some(self) -> Self::OutTuple;
}

impl<T> TupleAsOption for (T,) {
    type OutTuple = (Option<T>,);

    fn as_some(self) -> Self::OutTuple {
        (Some(self.0),)
    }
}

/// Mapping item to `Result` for Tuple
pub trait TupleAsResultOk<E> {
    type OutTuple;

    /// Mapping item to `Result::Ok` for Tuple
    fn as_ok(self) -> Self::OutTuple;
}

/// Mapping item to `Result` for Tuple
pub trait TupleAsResultErr<T> {
    type OutTuple;

    /// Mapping item to `Result::Err` for Tuple
    fn as_err(self) -> Self::OutTuple;
}

impl<T, E> TupleAsResultOk<E> for (T,) {
    type OutTuple = (Result<T, E>,);

    fn as_ok(self) -> Self::OutTuple {
        (Ok(self.0),)
    }
}

impl<T, O> TupleAsResultErr<O> for (T,) {
    type OutTuple = (Result<O, T>,);

    fn as_err(self) -> Self::OutTuple {
        (Err(self.0),)
    }
}

/// AsDeref for Tuple
pub trait TupleAsDeref<'a> {
    type OutTuple: 'a;

    /// AsDeref for Tuple
    fn as_deref(&'a self) -> Self::OutTuple;
}

impl<'a, T: 'a + Deref> TupleAsDeref<'a> for (T,) {
    type OutTuple = (&'a <T as Deref>::Target,);

    fn as_deref(&'a self) -> Self::OutTuple {
        (self.0.deref(),)
    }
}

/// AsDerefMut for Tuple
pub trait TupleAsDerefMut<'a> {
    type OutTuple: 'a;

    /// AsDerefMut for Tuple
    fn as_deref_mut(&'a mut self) -> Self::OutTuple;
}

impl<'a, T: 'a + DerefMut> TupleAsDerefMut<'a> for (T,) {
    type OutTuple = (&'a mut <T as Deref>::Target,);

    fn as_deref_mut(&'a mut self) -> Self::OutTuple {
        (self.0.deref_mut(),)
    }
}