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
crate::do_impl!("append", tuple_append, {
/// The resulting type when an element is appended to an initial tuple.
///
/// ```
/// use same_types::assert_same_types;
/// use tupleops::Append;
///
/// assert_same_types!(
/// Append<(u8, u16), u32>,
/// (u8, u16, u32),
/// );
/// ```
///
/// See also: [append()], [TupleAppend].
#[cfg_attr(docsrs, doc(cfg(feature = "append")))]
pub type Append<Init, Last> = <(Init, Last) as TupleAppend<Init, Last>>::Type;
/// Append an element to a tuple.
///
/// ```
/// use tupleops::append;
///
/// assert_eq!(
/// append((1, 2, 3), 4),
/// (1, 2, 3, 4),
/// );
/// ```
///
/// See also: [Append], [TupleAppend].
#[cfg_attr(docsrs, doc(cfg(feature = "append")))]
#[inline(always)]
pub fn append<Init, Last>(init: Init, last: Last) -> Append<Init, Last>
where
(Init, Last): TupleAppend<Init, Last>,
{
<(Init, Last) as TupleAppend<Init, Last>>::append(init, last)
}
/// A tuple and an element that are usable with [append()].
///
/// See also: [append()], [TupleAppend].
#[cfg_attr(docsrs, doc(cfg(feature = "append")))]
pub trait TupleAppend<Init, Last> {
#[doc(hidden)]
type Type;
#[doc(hidden)]
fn append(init: Init, last: Last) -> Self::Type;
}
impl<Last> TupleAppend<(), Last> for ((), Last) {
type Type = (Last,);
#[inline(always)]
fn append(init: (), last: Last) -> Self::Type {
let () = init;
(last,)
}
}
});