tupleops/tpl_append.rs
1crate::do_impl!("append", tuple_append, {
2 /// The resulting type when an element is appended to an initial tuple.
3 ///
4 /// ```
5 /// use same_types::assert_same_types;
6 /// use tupleops::Append;
7 ///
8 /// assert_same_types!(
9 /// Append<(u8, u16), u32>,
10 /// (u8, u16, u32),
11 /// );
12 /// ```
13 ///
14 /// See also: [append()], [TupleAppend].
15 #[cfg_attr(docsrs, doc(cfg(feature = "append")))]
16 pub type Append<Init, Last> = <(Init, Last) as TupleAppend<Init, Last>>::Type;
17
18 /// Append an element to a tuple.
19 ///
20 /// ```
21 /// use tupleops::append;
22 ///
23 /// assert_eq!(
24 /// append((1, 2, 3), 4),
25 /// (1, 2, 3, 4),
26 /// );
27 /// ```
28 ///
29 /// See also: [Append], [TupleAppend].
30 #[cfg_attr(docsrs, doc(cfg(feature = "append")))]
31 #[inline(always)]
32 pub fn append<Init, Last>(init: Init, last: Last) -> Append<Init, Last>
33 where
34 (Init, Last): TupleAppend<Init, Last>,
35 {
36 <(Init, Last) as TupleAppend<Init, Last>>::append(init, last)
37 }
38
39 /// A tuple and an element that are usable with [append()].
40 ///
41 /// See also: [append()], [TupleAppend].
42 #[cfg_attr(docsrs, doc(cfg(feature = "append")))]
43 pub trait TupleAppend<Init, Last> {
44 #[doc(hidden)]
45 type Type;
46
47 #[doc(hidden)]
48 fn append(init: Init, last: Last) -> Self::Type;
49 }
50
51 impl<Last> TupleAppend<(), Last> for ((), Last) {
52 type Type = (Last,);
53
54 #[inline(always)]
55 fn append(init: (), last: Last) -> Self::Type {
56 let () = init;
57 (last,)
58 }
59 }
60});