Skip to main content

type_sets/
union.rs

1use super::*;
2
3/// Type alias for the union of two type sets.
4///
5/// # Example
6///
7/// ```rust
8/// # use type_sets::*;
9/// assert::eq::<Union<(i32,), (i16,)>, (i32, i16)>();
10/// ```
11pub type Union<T, R> = <T as Extend<R>>::Output;
12
13/// Trait for extending a type set with another type set.
14///
15/// See [`Union`] for a convenient type alias to compute the union of two type sets.
16pub trait Extend<T: ?Sized> {
17    type Output: ?Sized;
18}
19
20impl<T> Extend<()> for T {
21    type Output = T;
22}
23
24impl<T, E1> Extend<(E1,)> for T
25where
26    T: Push,
27{
28    type Output = <T::Output<E1> as Extend<()>>::Output;
29}
30
31impl<T, E1, E2> Extend<(E1, E2)> for T
32where
33    T: Push<Output<E1>: Push>,
34{
35    type Output = <T::Output<E1> as Extend<(E2,)>>::Output;
36}
37
38impl<T, E1, E2, E3> Extend<(E1, E2, E3)> for T
39where
40    T: Push<Output<E1>: Push<Output<E2>: Push>>,
41{
42    type Output = <T::Output<E1> as Extend<(E2, E3)>>::Output;
43}
44
45impl<T, E1, E2, E3, E4> Extend<(E1, E2, E3, E4)> for T
46where
47    T: Push<Output<E1>: Push<Output<E2>: Push<Output<E3>: Push>>>,
48{
49    type Output = <T::Output<E1> as Extend<(E2, E3, E4)>>::Output;
50}
51
52impl<T, E1, E2, E3, E4, E5> Extend<(E1, E2, E3, E4, E5)> for T
53where
54    T: Push<Output<E1>: Push<Output<E2>: Push<Output<E3>: Push<Output<E4>: Push>>>>,
55{
56    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5)>>::Output;
57}
58
59impl<T, E1, E2, E3, E4, E5, E6> Extend<(E1, E2, E3, E4, E5, E6)> for T
60where
61    T: Push<
62        Output<E1>: Push<Output<E2>: Push<Output<E3>: Push<Output<E4>: Push<Output<E5>: Push>>>>,
63    >,
64{
65    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6)>>::Output;
66}
67
68impl<T, E1, E2, E3, E4, E5, E6, E7> Extend<(E1, E2, E3, E4, E5, E6, E7)> for T
69where
70    T: Push<
71        Output<E1>: Push<
72            Output<E2>: Push<
73                Output<E3>: Push<Output<E4>: Push<Output<E5>: Push<Output<E6>: Push>>>,
74            >,
75        >,
76    >,
77{
78    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7)>>::Output;
79}
80
81impl<T, E1, E2, E3, E4, E5, E6, E7, E8> Extend<(E1, E2, E3, E4, E5, E6, E7, E8)> for T
82where
83    T: Push<
84        Output<E1>: Push<
85            Output<E2>: Push<
86                Output<E3>: Push<
87                    Output<E4>: Push<Output<E5>: Push<Output<E6>: Push<Output<E7>: Push>>>,
88                >,
89            >,
90        >,
91    >,
92{
93    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7, E8)>>::Output;
94}
95
96impl<T, E1, E2, E3, E4, E5, E6, E7, E8, E9> Extend<(E1, E2, E3, E4, E5, E6, E7, E8, E9)> for T
97where
98    T: Push<
99        Output<E1>: Push<
100            Output<E2>: Push<
101                Output<E3>: Push<
102                    Output<E4>: Push<
103                        Output<E5>: Push<Output<E6>: Push<Output<E7>: Push<Output<E8>: Push>>>,
104                    >,
105                >,
106            >,
107        >,
108    >,
109{
110    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7, E8, E9)>>::Output;
111}
112
113impl<T, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10> Extend<(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10)>
114    for T
115where
116    T: Push<
117        Output<E1>: Push<
118            Output<E2>: Push<
119                Output<E3>: Push<
120                    Output<E4>: Push<
121                        Output<E5>: Push<
122                            Output<E6>: Push<Output<E7>: Push<Output<E8>: Push<Output<E9>: Push>>>,
123                        >,
124                    >,
125                >,
126            >,
127        >,
128    >,
129{
130    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7, E8, E9, E10)>>::Output;
131}
132
133impl<T, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11>
134    Extend<(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11)> for T
135where
136    T: Push<
137        Output<E1>: Push<
138            Output<E2>: Push<
139                Output<E3>: Push<
140                    Output<E4>: Push<
141                        Output<E5>: Push<
142                            Output<E6>: Push<
143                                Output<E7>: Push<
144                                    Output<E8>: Push<Output<E9>: Push<Output<E10>: Push>>,
145                                >,
146                            >,
147                        >,
148                    >,
149                >,
150            >,
151        >,
152    >,
153{
154    type Output = <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7, E8, E9, E10, E11)>>::Output;
155}
156
157impl<T, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12>
158    Extend<(E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12)> for T
159where
160    T: Push<
161        Output<E1>: Push<
162            Output<E2>: Push<
163                Output<E3>: Push<
164                    Output<E4>: Push<
165                        Output<E5>: Push<
166                            Output<E6>: Push<
167                                Output<E7>: Push<
168                                    Output<E8>: Push<
169                                        Output<E9>: Push<Output<E10>: Push<Output<E11>: Push>>,
170                                    >,
171                                >,
172                            >,
173                        >,
174                    >,
175                >,
176            >,
177        >,
178    >,
179{
180    type Output =
181        <T::Output<E1> as Extend<(E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12)>>::Output;
182}