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
crate::do_impl!("unprepend", tuple_unprepend, {
/// The type of the first element of the tuple.
///
/// ```
/// use same_types::assert_same_types;
/// use tupleops::Head;
///
/// assert_same_types!(
/// Head<(u8, u16, u32)>,
/// u8,
/// );
/// ```
///
/// See also: [unprepend()], [Tail], [TupleUnprepend].
#[cfg_attr(docsrs, doc(cfg(feature = "unprepend")))]
pub type Head<Tpl> = <Tpl as TupleUnprepend<Tpl>>::Head;
/// The resulting tuple when the first element is removed from a tuple.
///
/// ```
/// use same_types::assert_same_types;
/// use tupleops::Tail;
///
/// assert_same_types!(
/// Tail<(u8, u16, u32)>,
/// (u16, u32),
/// );
/// ```
///
/// See also: [unprepend()], [Tail], [TupleUnprepend].
#[cfg_attr(docsrs, doc(cfg(feature = "unprepend")))]
pub type Tail<Tpl> = <Tpl as TupleUnprepend<Tpl>>::Tail;
/// Extract the first element of a tuple, and return a tuple of the first element and the
/// last elements of the tuple.
///
/// ```
/// use tupleops::unprepend;
///
/// assert_eq!(
/// unprepend((1, 2, 3, 4)),
/// (1, (2, 3, 4)),
/// );
/// ```
///
/// See also: [Head], [Tail], [TupleUnprepend].
#[cfg_attr(docsrs, doc(cfg(feature = "unprepend")))]
#[inline(always)]
pub fn unprepend<Tpl>(tpl: Tpl) -> (Head<Tpl>, Tail<Tpl>)
where
Tpl: TupleUnprepend<Tpl>,
{
<Tpl as TupleUnprepend<Tpl>>::unprepend(tpl)
}
/// A tuple that is usable with [unprepend()].
///
/// See also: [unprepend()], [Head], [Tail].
#[cfg_attr(docsrs, doc(cfg(feature = "unprepend")))]
pub trait TupleUnprepend<Tpl> {
#[doc(hidden)]
type Head;
#[doc(hidden)]
type Tail;
#[doc(hidden)]
fn unprepend(tpl: Tpl) -> (Self::Head, Self::Tail);
}
impl<Elem> TupleUnprepend<(Elem,)> for (Elem,) {
type Head = Elem;
type Tail = ();
#[inline(always)]
fn unprepend(tpl: (Elem,)) -> (Self::Head, Self::Tail) {
let (head,) = tpl;
(head, ())
}
}
});