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
crate::do_impl!("concat-many", tuple_concat_many, {
use crate::{concat_tuples, ConcatTuples, TupleConcat};
/// The resulting type when two or more tuples are concatenated.
///
/// ```
/// use same_types::assert_same_types;
/// use tupleops::ConcatMany;
///
/// assert_same_types!(
/// ConcatMany<()>,
/// ()
/// );
///
/// assert_same_types!(
/// ConcatMany<((u8, u16),)>,
/// (u8, u16)
/// );
///
/// assert_same_types!(
/// ConcatMany<((u8, u16), (u32, u64), (i8, i16), (i32, i64))>,
/// (u8, u16, u32, u64, i8, i16, i32, i64)
/// );
/// ```
///
/// See also: [concat_many()], [TupleConcatMany].
#[cfg_attr(docsrs, doc(cfg(feature = "concat-many")))]
pub type ConcatMany<Tpls> = <Tpls as TupleConcatMany<Tpls>>::Type;
/// Concatenate two or more tuples.
///
/// ```
/// use tupleops::concat_many;
///
/// assert_eq!(
/// concat_many(()),
/// (),
/// );
///
/// assert_eq!(
/// concat_many(((1, 2, 3),)),
/// (1, 2, 3),
/// );
///
/// assert_eq!(
/// concat_many(((), (1,), (2, 3,), (4, 5, 6))),
/// (1, 2, 3, 4, 5, 6),
/// );
/// ```
///
/// See also: [ConcatMany], [TupleConcatMany].
#[cfg_attr(docsrs, doc(cfg(feature = "concat-many")))]
#[inline(always)]
pub fn concat_many<Tpls>(tpls: Tpls) -> ConcatMany<Tpls>
where
Tpls: TupleConcatMany<Tpls>,
{
<Tpls as TupleConcatMany<Tpls>>::concat_many(tpls)
}
/// A tuple of tuples that is usable with [concat_many()].
///
/// See also: [concat_many], [TupleConcatMany].
#[cfg_attr(docsrs, doc(cfg(feature = "concat-many")))]
pub trait TupleConcatMany<Tpls> {
#[doc(hidden)]
type Type;
#[doc(hidden)]
fn concat_many(tpls: Tpls) -> Self::Type;
}
impl TupleConcatMany<()> for () {
type Type = ();
#[inline(always)]
fn concat_many(tpls: ()) -> Self::Type {
let () = tpls;
}
}
impl<I1> TupleConcatMany<(I1,)> for (I1,) {
type Type = I1;
#[inline(always)]
fn concat_many(tpls: (I1,)) -> Self::Type {
let (tpl,) = tpls;
tpl
}
}
impl<Z1, Z2> TupleConcatMany<(Z1, Z2)> for (Z1, Z2)
where
(Z1, Z2): TupleConcat<Z1, Z2>,
{
type Type = ConcatTuples<Z1, Z2>;
#[inline(always)]
fn concat_many(tpls: (Z1, Z2)) -> Self::Type {
let (z1, z2) = tpls;
concat_tuples(z1, z2)
}
}
});