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