or_rs/
enums.rs

1//! A concrete implementation of the type Or that represents values of multiple types.
2//!
3//! Different enum types `OrX` (where X is the number of types the enum can contain) are provided
4//! depending on the number of types it can contain.
5//!
6//! The implementation of these enums includes several basic function such as `is_tx`
7//! for assertion and `as_tx` for cast, and also have some util functions, like `map`, `fold`.
8
9use std::any::TypeId;
10
11/// `Or2` is an enum representing a value that can be either of 2 types, T1 ... T2.
12pub enum Or2<T1, T2> {
13    T1(T1),
14    T2(T2),
15}
16
17impl<T1, T2> Or2<T1, T2> {
18    /// Returns true if the enum is of type T1.
19    pub fn is_t1(&self) -> bool {
20        match self {
21            Self::T1(_) => true,
22            _ => false,
23        }
24    }
25
26    /// Returns true if the enum is of type T2.
27    pub fn is_t2(&self) -> bool {
28        match self {
29            Self::T2(_) => true,
30            _ => false,
31        }
32    }
33
34    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
35    pub fn as_t1(self) -> Option<T1> {
36        match self {
37            Self::T1(t1) => Some(t1),
38            _ => None,
39        }
40    }
41
42    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
43    pub fn as_t2(self) -> Option<T2> {
44        match self {
45            Self::T2(t2) => Some(t2),
46            _ => None,
47        }
48    }
49
50    /// Transforms the T1 value of the enum using a provided function,
51    /// maintaining other types as is.
52    pub fn map_t1<F, B>(self, f: F) -> Or2<B, T2>
53    where
54        F: FnOnce(T1) -> B,
55    {
56        match self {
57            Self::T1(t1) => Or2::<B, T2>::T1(f(t1)),
58            Self::T2(t2) => Or2::<B, T2>::T2(t2),
59        }
60    }
61
62    /// Transforms the T2 value of the enum using a provided function,
63    /// maintaining other types as is.
64    pub fn map_t2<F, B>(self, f: F) -> Or2<T1, B>
65    where
66        F: FnOnce(T2) -> B,
67    {
68        match self {
69            Self::T1(t1) => Or2::<T1, B>::T1(t1),
70            Self::T2(t2) => Or2::<T1, B>::T2(f(t2)),
71        }
72    }
73
74    /// Consolidates the `Or2` enum into a single value of type `T`,
75    /// by applying provided functions.
76    pub fn fold<T, F0, F1, F2>(self, f1: F1, f2: F2) -> T
77    where
78        F1: FnOnce(T1) -> T,
79        F2: FnOnce(T2) -> T,
80    {
81        match self {
82            Self::T1(t1) => f1(t1),
83            Self::T2(t2) => f2(t2),
84        }
85    }
86}
87
88/// Extension to `Or2` to check if the enum's type matches a arbitrary type.
89/// Currently, these functions depend on the rustc intrinsics, and the constraints
90/// of the intrinsics require that the type must satisfy `'static'`.
91impl<T1, T2> Or2<T1, T2>
92where
93    T1: 'static,
94    T2: 'static,
95{
96    pub fn is_type<T: 'static>(&self) -> bool {
97        match self {
98            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
99            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
100        }
101    }
102}
103
104/// `Or3` is an enum representing a value that can be either of 3 types, T1 ... T3.
105#[derive(Clone, Copy)]
106pub enum Or3<T1, T2, T3> {
107    T1(T1),
108    T2(T2),
109    T3(T3),
110}
111
112impl<T1, T2, T3> Or3<T1, T2, T3> {
113    /// Returns true if the enum is of type T1.
114    pub fn is_t1(&self) -> bool {
115        match self {
116            Self::T1(_) => true,
117            _ => false,
118        }
119    }
120
121    /// Returns true if the enum is of type T2.
122    pub fn is_t2(&self) -> bool {
123        match self {
124            Self::T2(_) => true,
125            _ => false,
126        }
127    }
128
129    /// Returns true if the enum is of type T3.
130    pub fn is_t3(&self) -> bool {
131        match self {
132            Self::T3(_) => true,
133            _ => false,
134        }
135    }
136
137    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
138    pub fn as_t1(self) -> Option<T1> {
139        match self {
140            Self::T1(t1) => Some(t1),
141            _ => None,
142        }
143    }
144
145    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
146    pub fn as_t2(self) -> Option<T2> {
147        match self {
148            Self::T2(t2) => Some(t2),
149            _ => None,
150        }
151    }
152
153    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
154    pub fn as_t3(self) -> Option<T3> {
155        match self {
156            Self::T3(t3) => Some(t3),
157            _ => None,
158        }
159    }
160
161    /// Transforms the T1 value of the enum using a provided function,
162    /// maintaining other types as is.
163    pub fn map_t1<F, B>(self, f: F) -> Or3<B, T2, T3>
164    where
165        F: FnOnce(T1) -> B,
166    {
167        match self {
168            Self::T1(t1) => Or3::<B, T2, T3>::T1(f(t1)),
169            Self::T2(t2) => Or3::<B, T2, T3>::T2(t2),
170            Self::T3(t3) => Or3::<B, T2, T3>::T3(t3),
171        }
172    }
173
174    /// Transforms the T2 value of the enum using a provided function,
175    /// maintaining other types as is.
176    pub fn map_t2<F, B>(self, f: F) -> Or3<T1, B, T3>
177    where
178        F: FnOnce(T2) -> B,
179    {
180        match self {
181            Self::T1(t1) => Or3::<T1, B, T3>::T1(t1),
182            Self::T2(t2) => Or3::<T1, B, T3>::T2(f(t2)),
183            Self::T3(t3) => Or3::<T1, B, T3>::T3(t3),
184        }
185    }
186
187    /// Transforms the T3 value of the enum using a provided function,
188    /// maintaining other types as is.
189    pub fn map_t3<F, B>(self, f: F) -> Or3<T1, T2, B>
190    where
191        F: FnOnce(T3) -> B,
192    {
193        match self {
194            Self::T1(t1) => Or3::<T1, T2, B>::T1(t1),
195            Self::T2(t2) => Or3::<T1, T2, B>::T2(t2),
196            Self::T3(t3) => Or3::<T1, T2, B>::T3(f(t3)),
197        }
198    }
199
200    /// Consolidates the `Or3` enum into a single value of type `T`,
201    /// by applying provided functions.
202    pub fn fold<T, F0, F1, F2, F3>(self, f1: F1, f2: F2, f3: F3) -> T
203    where
204        F1: FnOnce(T1) -> T,
205        F2: FnOnce(T2) -> T,
206        F3: FnOnce(T3) -> T,
207    {
208        match self {
209            Self::T1(t1) => f1(t1),
210            Self::T2(t2) => f2(t2),
211            Self::T3(t3) => f3(t3),
212        }
213    }
214}
215
216/// Extension to `Or3` to check if the enum's type matches a arbitrary type.
217/// Currently, these functions depend on the rustc intrinsics, and the constraints
218/// of the intrinsics require that the type must satisfy `'static'`.
219impl<T1, T2, T3> Or3<T1, T2, T3>
220where
221    T1: 'static,
222    T2: 'static,
223    T3: 'static,
224{
225    pub fn is_type<T: 'static>(&self) -> bool {
226        match self {
227            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
228            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
229            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
230        }
231    }
232}
233
234/// `Or4` is an enum representing a value that can be either of 4 types, T1 ... T4.
235pub enum Or4<T1, T2, T3, T4> {
236    T1(T1),
237    T2(T2),
238    T3(T3),
239    T4(T4),
240}
241
242impl<T1, T2, T3, T4> Or4<T1, T2, T3, T4> {
243    /// Returns true if the enum is of type T1.
244    pub fn is_t1(&self) -> bool {
245        match self {
246            Self::T1(_) => true,
247            _ => false,
248        }
249    }
250
251    /// Returns true if the enum is of type T2.
252    pub fn is_t2(&self) -> bool {
253        match self {
254            Self::T2(_) => true,
255            _ => false,
256        }
257    }
258
259    /// Returns true if the enum is of type T3.
260    pub fn is_t3(&self) -> bool {
261        match self {
262            Self::T3(_) => true,
263            _ => false,
264        }
265    }
266
267    /// Returns true if the enum is of type T4.
268    pub fn is_t4(&self) -> bool {
269        match self {
270            Self::T4(_) => true,
271            _ => false,
272        }
273    }
274
275    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
276    pub fn as_t1(self) -> Option<T1> {
277        match self {
278            Self::T1(t1) => Some(t1),
279            _ => None,
280        }
281    }
282
283    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
284    pub fn as_t2(self) -> Option<T2> {
285        match self {
286            Self::T2(t2) => Some(t2),
287            _ => None,
288        }
289    }
290
291    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
292    pub fn as_t3(self) -> Option<T3> {
293        match self {
294            Self::T3(t3) => Some(t3),
295            _ => None,
296        }
297    }
298
299    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
300    pub fn as_t4(self) -> Option<T4> {
301        match self {
302            Self::T4(t4) => Some(t4),
303            _ => None,
304        }
305    }
306
307    /// Transforms the T1 value of the enum using a provided function,
308    /// maintaining other types as is.
309    pub fn map_t1<F, B>(self, f: F) -> Or4<B, T2, T3, T4>
310    where
311        F: FnOnce(T1) -> B,
312    {
313        match self {
314            Self::T1(t1) => Or4::<B, T2, T3, T4>::T1(f(t1)),
315            Self::T2(t2) => Or4::<B, T2, T3, T4>::T2(t2),
316            Self::T3(t3) => Or4::<B, T2, T3, T4>::T3(t3),
317            Self::T4(t4) => Or4::<B, T2, T3, T4>::T4(t4),
318        }
319    }
320
321    /// Transforms the T2 value of the enum using a provided function,
322    /// maintaining other types as is.
323    pub fn map_t2<F, B>(self, f: F) -> Or4<T1, B, T3, T4>
324    where
325        F: FnOnce(T2) -> B,
326    {
327        match self {
328            Self::T1(t1) => Or4::<T1, B, T3, T4>::T1(t1),
329            Self::T2(t2) => Or4::<T1, B, T3, T4>::T2(f(t2)),
330            Self::T3(t3) => Or4::<T1, B, T3, T4>::T3(t3),
331            Self::T4(t4) => Or4::<T1, B, T3, T4>::T4(t4),
332        }
333    }
334
335    /// Transforms the T3 value of the enum using a provided function,
336    /// maintaining other types as is.
337    pub fn map_t3<F, B>(self, f: F) -> Or4<T1, T2, B, T4>
338    where
339        F: FnOnce(T3) -> B,
340    {
341        match self {
342            Self::T1(t1) => Or4::<T1, T2, B, T4>::T1(t1),
343            Self::T2(t2) => Or4::<T1, T2, B, T4>::T2(t2),
344            Self::T3(t3) => Or4::<T1, T2, B, T4>::T3(f(t3)),
345            Self::T4(t4) => Or4::<T1, T2, B, T4>::T4(t4),
346        }
347    }
348
349    /// Transforms the T4 value of the enum using a provided function,
350    /// maintaining other types as is.
351    pub fn map_t4<F, B>(self, f: F) -> Or4<T1, T2, T3, B>
352    where
353        F: FnOnce(T4) -> B,
354    {
355        match self {
356            Self::T1(t1) => Or4::<T1, T2, T3, B>::T1(t1),
357            Self::T2(t2) => Or4::<T1, T2, T3, B>::T2(t2),
358            Self::T3(t3) => Or4::<T1, T2, T3, B>::T3(t3),
359            Self::T4(t4) => Or4::<T1, T2, T3, B>::T4(f(t4)),
360        }
361    }
362
363    /// Consolidates the `Or4` enum into a single value of type `T`,
364    /// by applying provided functions.
365    pub fn fold<T, F0, F1, F2, F3, F4>(self, f1: F1, f2: F2, f3: F3, f4: F4) -> T
366    where
367        F1: FnOnce(T1) -> T,
368        F2: FnOnce(T2) -> T,
369        F3: FnOnce(T3) -> T,
370        F4: FnOnce(T4) -> T,
371    {
372        match self {
373            Self::T1(t1) => f1(t1),
374            Self::T2(t2) => f2(t2),
375            Self::T3(t3) => f3(t3),
376            Self::T4(t4) => f4(t4),
377        }
378    }
379}
380
381/// Extension to `Or4` to check if the enum's type matches a arbitrary type.
382/// Currently, these functions depend on the rustc intrinsics, and the constraints
383/// of the intrinsics require that the type must satisfy `'static'`.
384impl<T1, T2, T3, T4> Or4<T1, T2, T3, T4>
385where
386    T1: 'static,
387    T2: 'static,
388    T3: 'static,
389    T4: 'static,
390{
391    pub fn is_type<T: 'static>(&self) -> bool {
392        match self {
393            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
394            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
395            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
396            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
397        }
398    }
399}
400
401/// `Or5` is an enum representing a value that can be either of 5 types, T1 ... T5.
402pub enum Or5<T1, T2, T3, T4, T5> {
403    T1(T1),
404    T2(T2),
405    T3(T3),
406    T4(T4),
407    T5(T5),
408}
409
410impl<T1, T2, T3, T4, T5> Or5<T1, T2, T3, T4, T5> {
411    /// Returns true if the enum is of type T1.
412    pub fn is_t1(&self) -> bool {
413        match self {
414            Self::T1(_) => true,
415            _ => false,
416        }
417    }
418
419    /// Returns true if the enum is of type T2.
420    pub fn is_t2(&self) -> bool {
421        match self {
422            Self::T2(_) => true,
423            _ => false,
424        }
425    }
426
427    /// Returns true if the enum is of type T3.
428    pub fn is_t3(&self) -> bool {
429        match self {
430            Self::T3(_) => true,
431            _ => false,
432        }
433    }
434
435    /// Returns true if the enum is of type T4.
436    pub fn is_t4(&self) -> bool {
437        match self {
438            Self::T4(_) => true,
439            _ => false,
440        }
441    }
442
443    /// Returns true if the enum is of type T5.
444    pub fn is_t5(&self) -> bool {
445        match self {
446            Self::T5(_) => true,
447            _ => false,
448        }
449    }
450
451    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
452    pub fn as_t1(self) -> Option<T1> {
453        match self {
454            Self::T1(t1) => Some(t1),
455            _ => None,
456        }
457    }
458
459    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
460    pub fn as_t2(self) -> Option<T2> {
461        match self {
462            Self::T2(t2) => Some(t2),
463            _ => None,
464        }
465    }
466
467    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
468    pub fn as_t3(self) -> Option<T3> {
469        match self {
470            Self::T3(t3) => Some(t3),
471            _ => None,
472        }
473    }
474
475    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
476    pub fn as_t4(self) -> Option<T4> {
477        match self {
478            Self::T4(t4) => Some(t4),
479            _ => None,
480        }
481    }
482
483    /// Converts the enum to an Option containing the T5 value, if it is of type T5.
484    pub fn as_t5(self) -> Option<T5> {
485        match self {
486            Self::T5(t5) => Some(t5),
487            _ => None,
488        }
489    }
490
491    /// Transforms the T1 value of the enum using a provided function,
492    /// maintaining other types as is.
493    pub fn map_t1<F, B>(self, f: F) -> Or5<B, T2, T3, T4, T5>
494    where
495        F: FnOnce(T1) -> B,
496    {
497        match self {
498            Self::T1(t1) => Or5::<B, T2, T3, T4, T5>::T1(f(t1)),
499            Self::T2(t2) => Or5::<B, T2, T3, T4, T5>::T2(t2),
500            Self::T3(t3) => Or5::<B, T2, T3, T4, T5>::T3(t3),
501            Self::T4(t4) => Or5::<B, T2, T3, T4, T5>::T4(t4),
502            Self::T5(t5) => Or5::<B, T2, T3, T4, T5>::T5(t5),
503        }
504    }
505
506    /// Transforms the T2 value of the enum using a provided function,
507    /// maintaining other types as is.
508    pub fn map_t2<F, B>(self, f: F) -> Or5<T1, B, T3, T4, T5>
509    where
510        F: FnOnce(T2) -> B,
511    {
512        match self {
513            Self::T1(t1) => Or5::<T1, B, T3, T4, T5>::T1(t1),
514            Self::T2(t2) => Or5::<T1, B, T3, T4, T5>::T2(f(t2)),
515            Self::T3(t3) => Or5::<T1, B, T3, T4, T5>::T3(t3),
516            Self::T4(t4) => Or5::<T1, B, T3, T4, T5>::T4(t4),
517            Self::T5(t5) => Or5::<T1, B, T3, T4, T5>::T5(t5),
518        }
519    }
520
521    /// Transforms the T3 value of the enum using a provided function,
522    /// maintaining other types as is.
523    pub fn map_t3<F, B>(self, f: F) -> Or5<T1, T2, B, T4, T5>
524    where
525        F: FnOnce(T3) -> B,
526    {
527        match self {
528            Self::T1(t1) => Or5::<T1, T2, B, T4, T5>::T1(t1),
529            Self::T2(t2) => Or5::<T1, T2, B, T4, T5>::T2(t2),
530            Self::T3(t3) => Or5::<T1, T2, B, T4, T5>::T3(f(t3)),
531            Self::T4(t4) => Or5::<T1, T2, B, T4, T5>::T4(t4),
532            Self::T5(t5) => Or5::<T1, T2, B, T4, T5>::T5(t5),
533        }
534    }
535
536    /// Transforms the T4 value of the enum using a provided function,
537    /// maintaining other types as is.
538    pub fn map_t4<F, B>(self, f: F) -> Or5<T1, T2, T3, B, T5>
539    where
540        F: FnOnce(T4) -> B,
541    {
542        match self {
543            Self::T1(t1) => Or5::<T1, T2, T3, B, T5>::T1(t1),
544            Self::T2(t2) => Or5::<T1, T2, T3, B, T5>::T2(t2),
545            Self::T3(t3) => Or5::<T1, T2, T3, B, T5>::T3(t3),
546            Self::T4(t4) => Or5::<T1, T2, T3, B, T5>::T4(f(t4)),
547            Self::T5(t5) => Or5::<T1, T2, T3, B, T5>::T5(t5),
548        }
549    }
550
551    /// Transforms the T5 value of the enum using a provided function,
552    /// maintaining other types as is.
553    pub fn map_t5<F, B>(self, f: F) -> Or5<T1, T2, T3, T4, B>
554    where
555        F: FnOnce(T5) -> B,
556    {
557        match self {
558            Self::T1(t1) => Or5::<T1, T2, T3, T4, B>::T1(t1),
559            Self::T2(t2) => Or5::<T1, T2, T3, T4, B>::T2(t2),
560            Self::T3(t3) => Or5::<T1, T2, T3, T4, B>::T3(t3),
561            Self::T4(t4) => Or5::<T1, T2, T3, T4, B>::T4(t4),
562            Self::T5(t5) => Or5::<T1, T2, T3, T4, B>::T5(f(t5)),
563        }
564    }
565
566    /// Consolidates the `Or5` enum into a single value of type `T`,
567    /// by applying provided functions.
568    pub fn fold<T, F0, F1, F2, F3, F4, F5>(self, f1: F1, f2: F2, f3: F3, f4: F4, f5: F5) -> T
569    where
570        F1: FnOnce(T1) -> T,
571        F2: FnOnce(T2) -> T,
572        F3: FnOnce(T3) -> T,
573        F4: FnOnce(T4) -> T,
574        F5: FnOnce(T5) -> T,
575    {
576        match self {
577            Self::T1(t1) => f1(t1),
578            Self::T2(t2) => f2(t2),
579            Self::T3(t3) => f3(t3),
580            Self::T4(t4) => f4(t4),
581            Self::T5(t5) => f5(t5),
582        }
583    }
584}
585
586/// Extension to `Or5` to check if the enum's type matches a arbitrary type.
587/// Currently, these functions depend on the rustc intrinsics, and the constraints
588/// of the intrinsics require that the type must satisfy `'static'`.
589impl<T1, T2, T3, T4, T5> Or5<T1, T2, T3, T4, T5>
590where
591    T1: 'static,
592    T2: 'static,
593    T3: 'static,
594    T4: 'static,
595    T5: 'static,
596{
597    pub fn is_type<T: 'static>(&self) -> bool {
598        match self {
599            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
600            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
601            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
602            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
603            Self::T5(_) => TypeId::of::<T>() == TypeId::of::<T5>(),
604        }
605    }
606}
607
608/// `Or6` is an enum representing a value that can be either of 6 types, T1 ... T6.
609pub enum Or6<T1, T2, T3, T4, T5, T6> {
610    T1(T1),
611    T2(T2),
612    T3(T3),
613    T4(T4),
614    T5(T5),
615    T6(T6),
616}
617
618impl<T1, T2, T3, T4, T5, T6> Or6<T1, T2, T3, T4, T5, T6> {
619    /// Returns true if the enum is of type T1.
620    pub fn is_t1(&self) -> bool {
621        match self {
622            Self::T1(_) => true,
623            _ => false,
624        }
625    }
626
627    /// Returns true if the enum is of type T2.
628    pub fn is_t2(&self) -> bool {
629        match self {
630            Self::T2(_) => true,
631            _ => false,
632        }
633    }
634
635    /// Returns true if the enum is of type T3.
636    pub fn is_t3(&self) -> bool {
637        match self {
638            Self::T3(_) => true,
639            _ => false,
640        }
641    }
642
643    /// Returns true if the enum is of type T4.
644    pub fn is_t4(&self) -> bool {
645        match self {
646            Self::T4(_) => true,
647            _ => false,
648        }
649    }
650
651    /// Returns true if the enum is of type T5.
652    pub fn is_t5(&self) -> bool {
653        match self {
654            Self::T5(_) => true,
655            _ => false,
656        }
657    }
658
659    /// Returns true if the enum is of type T6.
660    pub fn is_t6(&self) -> bool {
661        match self {
662            Self::T6(_) => true,
663            _ => false,
664        }
665    }
666
667    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
668    pub fn as_t1(self) -> Option<T1> {
669        match self {
670            Self::T1(t1) => Some(t1),
671            _ => None,
672        }
673    }
674
675    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
676    pub fn as_t2(self) -> Option<T2> {
677        match self {
678            Self::T2(t2) => Some(t2),
679            _ => None,
680        }
681    }
682
683    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
684    pub fn as_t3(self) -> Option<T3> {
685        match self {
686            Self::T3(t3) => Some(t3),
687            _ => None,
688        }
689    }
690
691    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
692    pub fn as_t4(self) -> Option<T4> {
693        match self {
694            Self::T4(t4) => Some(t4),
695            _ => None,
696        }
697    }
698
699    /// Converts the enum to an Option containing the T5 value, if it is of type T5.
700    pub fn as_t5(self) -> Option<T5> {
701        match self {
702            Self::T5(t5) => Some(t5),
703            _ => None,
704        }
705    }
706
707    /// Converts the enum to an Option containing the T6 value, if it is of type T6.
708    pub fn as_t6(self) -> Option<T6> {
709        match self {
710            Self::T6(t6) => Some(t6),
711            _ => None,
712        }
713    }
714
715    /// Transforms the T1 value of the enum using a provided function,
716    /// maintaining other types as is.
717    pub fn map_t1<F, B>(self, f: F) -> Or6<B, T2, T3, T4, T5, T6>
718    where
719        F: FnOnce(T1) -> B,
720    {
721        match self {
722            Self::T1(t1) => Or6::<B, T2, T3, T4, T5, T6>::T1(f(t1)),
723            Self::T2(t2) => Or6::<B, T2, T3, T4, T5, T6>::T2(t2),
724            Self::T3(t3) => Or6::<B, T2, T3, T4, T5, T6>::T3(t3),
725            Self::T4(t4) => Or6::<B, T2, T3, T4, T5, T6>::T4(t4),
726            Self::T5(t5) => Or6::<B, T2, T3, T4, T5, T6>::T5(t5),
727            Self::T6(t6) => Or6::<B, T2, T3, T4, T5, T6>::T6(t6),
728        }
729    }
730
731    /// Transforms the T2 value of the enum using a provided function,
732    /// maintaining other types as is.
733    pub fn map_t2<F, B>(self, f: F) -> Or6<T1, B, T3, T4, T5, T6>
734    where
735        F: FnOnce(T2) -> B,
736    {
737        match self {
738            Self::T1(t1) => Or6::<T1, B, T3, T4, T5, T6>::T1(t1),
739            Self::T2(t2) => Or6::<T1, B, T3, T4, T5, T6>::T2(f(t2)),
740            Self::T3(t3) => Or6::<T1, B, T3, T4, T5, T6>::T3(t3),
741            Self::T4(t4) => Or6::<T1, B, T3, T4, T5, T6>::T4(t4),
742            Self::T5(t5) => Or6::<T1, B, T3, T4, T5, T6>::T5(t5),
743            Self::T6(t6) => Or6::<T1, B, T3, T4, T5, T6>::T6(t6),
744        }
745    }
746
747    /// Transforms the T3 value of the enum using a provided function,
748    /// maintaining other types as is.
749    pub fn map_t3<F, B>(self, f: F) -> Or6<T1, T2, B, T4, T5, T6>
750    where
751        F: FnOnce(T3) -> B,
752    {
753        match self {
754            Self::T1(t1) => Or6::<T1, T2, B, T4, T5, T6>::T1(t1),
755            Self::T2(t2) => Or6::<T1, T2, B, T4, T5, T6>::T2(t2),
756            Self::T3(t3) => Or6::<T1, T2, B, T4, T5, T6>::T3(f(t3)),
757            Self::T4(t4) => Or6::<T1, T2, B, T4, T5, T6>::T4(t4),
758            Self::T5(t5) => Or6::<T1, T2, B, T4, T5, T6>::T5(t5),
759            Self::T6(t6) => Or6::<T1, T2, B, T4, T5, T6>::T6(t6),
760        }
761    }
762
763    /// Transforms the T4 value of the enum using a provided function,
764    /// maintaining other types as is.
765    pub fn map_t4<F, B>(self, f: F) -> Or6<T1, T2, T3, B, T5, T6>
766    where
767        F: FnOnce(T4) -> B,
768    {
769        match self {
770            Self::T1(t1) => Or6::<T1, T2, T3, B, T5, T6>::T1(t1),
771            Self::T2(t2) => Or6::<T1, T2, T3, B, T5, T6>::T2(t2),
772            Self::T3(t3) => Or6::<T1, T2, T3, B, T5, T6>::T3(t3),
773            Self::T4(t4) => Or6::<T1, T2, T3, B, T5, T6>::T4(f(t4)),
774            Self::T5(t5) => Or6::<T1, T2, T3, B, T5, T6>::T5(t5),
775            Self::T6(t6) => Or6::<T1, T2, T3, B, T5, T6>::T6(t6),
776        }
777    }
778
779    /// Transforms the T5 value of the enum using a provided function,
780    /// maintaining other types as is.
781    pub fn map_t5<F, B>(self, f: F) -> Or6<T1, T2, T3, T4, B, T6>
782    where
783        F: FnOnce(T5) -> B,
784    {
785        match self {
786            Self::T1(t1) => Or6::<T1, T2, T3, T4, B, T6>::T1(t1),
787            Self::T2(t2) => Or6::<T1, T2, T3, T4, B, T6>::T2(t2),
788            Self::T3(t3) => Or6::<T1, T2, T3, T4, B, T6>::T3(t3),
789            Self::T4(t4) => Or6::<T1, T2, T3, T4, B, T6>::T4(t4),
790            Self::T5(t5) => Or6::<T1, T2, T3, T4, B, T6>::T5(f(t5)),
791            Self::T6(t6) => Or6::<T1, T2, T3, T4, B, T6>::T6(t6),
792        }
793    }
794
795    /// Transforms the T6 value of the enum using a provided function,
796    /// maintaining other types as is.
797    pub fn map_t6<F, B>(self, f: F) -> Or6<T1, T2, T3, T4, T5, B>
798    where
799        F: FnOnce(T6) -> B,
800    {
801        match self {
802            Self::T1(t1) => Or6::<T1, T2, T3, T4, T5, B>::T1(t1),
803            Self::T2(t2) => Or6::<T1, T2, T3, T4, T5, B>::T2(t2),
804            Self::T3(t3) => Or6::<T1, T2, T3, T4, T5, B>::T3(t3),
805            Self::T4(t4) => Or6::<T1, T2, T3, T4, T5, B>::T4(t4),
806            Self::T5(t5) => Or6::<T1, T2, T3, T4, T5, B>::T5(t5),
807            Self::T6(t6) => Or6::<T1, T2, T3, T4, T5, B>::T6(f(t6)),
808        }
809    }
810
811    /// Consolidates the `Or6` enum into a single value of type `T`,
812    /// by applying provided functions.
813    pub fn fold<T, F0, F1, F2, F3, F4, F5, F6>(
814        self,
815        f1: F1,
816        f2: F2,
817        f3: F3,
818        f4: F4,
819        f5: F5,
820        f6: F6,
821    ) -> T
822    where
823        F1: FnOnce(T1) -> T,
824        F2: FnOnce(T2) -> T,
825        F3: FnOnce(T3) -> T,
826        F4: FnOnce(T4) -> T,
827        F5: FnOnce(T5) -> T,
828        F6: FnOnce(T6) -> T,
829    {
830        match self {
831            Self::T1(t1) => f1(t1),
832            Self::T2(t2) => f2(t2),
833            Self::T3(t3) => f3(t3),
834            Self::T4(t4) => f4(t4),
835            Self::T5(t5) => f5(t5),
836            Self::T6(t6) => f6(t6),
837        }
838    }
839}
840
841/// Extension to `Or6` to check if the enum's type matches a arbitrary type.
842/// Currently, these functions depend on the rustc intrinsics, and the constraints
843/// of the intrinsics require that the type must satisfy `'static'`.
844impl<T1, T2, T3, T4, T5, T6> Or6<T1, T2, T3, T4, T5, T6>
845where
846    T1: 'static,
847    T2: 'static,
848    T3: 'static,
849    T4: 'static,
850    T5: 'static,
851    T6: 'static,
852{
853    pub fn is_type<T: 'static>(&self) -> bool {
854        match self {
855            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
856            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
857            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
858            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
859            Self::T5(_) => TypeId::of::<T>() == TypeId::of::<T5>(),
860            Self::T6(_) => TypeId::of::<T>() == TypeId::of::<T6>(),
861        }
862    }
863}
864
865/// `Or7` is an enum representing a value that can be either of 7 types, T1 ... T7.
866pub enum Or7<T1, T2, T3, T4, T5, T6, T7> {
867    T1(T1),
868    T2(T2),
869    T3(T3),
870    T4(T4),
871    T5(T5),
872    T6(T6),
873    T7(T7),
874}
875
876impl<T1, T2, T3, T4, T5, T6, T7> Or7<T1, T2, T3, T4, T5, T6, T7> {
877    /// Returns true if the enum is of type T1.
878    pub fn is_t1(&self) -> bool {
879        match self {
880            Self::T1(_) => true,
881            _ => false,
882        }
883    }
884
885    /// Returns true if the enum is of type T2.
886    pub fn is_t2(&self) -> bool {
887        match self {
888            Self::T2(_) => true,
889            _ => false,
890        }
891    }
892
893    /// Returns true if the enum is of type T3.
894    pub fn is_t3(&self) -> bool {
895        match self {
896            Self::T3(_) => true,
897            _ => false,
898        }
899    }
900
901    /// Returns true if the enum is of type T4.
902    pub fn is_t4(&self) -> bool {
903        match self {
904            Self::T4(_) => true,
905            _ => false,
906        }
907    }
908
909    /// Returns true if the enum is of type T5.
910    pub fn is_t5(&self) -> bool {
911        match self {
912            Self::T5(_) => true,
913            _ => false,
914        }
915    }
916
917    /// Returns true if the enum is of type T6.
918    pub fn is_t6(&self) -> bool {
919        match self {
920            Self::T6(_) => true,
921            _ => false,
922        }
923    }
924
925    /// Returns true if the enum is of type T7.
926    pub fn is_t7(&self) -> bool {
927        match self {
928            Self::T7(_) => true,
929            _ => false,
930        }
931    }
932
933    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
934    pub fn as_t1(self) -> Option<T1> {
935        match self {
936            Self::T1(t1) => Some(t1),
937            _ => None,
938        }
939    }
940
941    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
942    pub fn as_t2(self) -> Option<T2> {
943        match self {
944            Self::T2(t2) => Some(t2),
945            _ => None,
946        }
947    }
948
949    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
950    pub fn as_t3(self) -> Option<T3> {
951        match self {
952            Self::T3(t3) => Some(t3),
953            _ => None,
954        }
955    }
956
957    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
958    pub fn as_t4(self) -> Option<T4> {
959        match self {
960            Self::T4(t4) => Some(t4),
961            _ => None,
962        }
963    }
964
965    /// Converts the enum to an Option containing the T5 value, if it is of type T5.
966    pub fn as_t5(self) -> Option<T5> {
967        match self {
968            Self::T5(t5) => Some(t5),
969            _ => None,
970        }
971    }
972
973    /// Converts the enum to an Option containing the T6 value, if it is of type T6.
974    pub fn as_t6(self) -> Option<T6> {
975        match self {
976            Self::T6(t6) => Some(t6),
977            _ => None,
978        }
979    }
980
981    /// Converts the enum to an Option containing the T7 value, if it is of type T7.
982    pub fn as_t7(self) -> Option<T7> {
983        match self {
984            Self::T7(t7) => Some(t7),
985            _ => None,
986        }
987    }
988
989    /// Transforms the T1 value of the enum using a provided function,
990    /// maintaining other types as is.
991    pub fn map_t1<F, B>(self, f: F) -> Or7<B, T2, T3, T4, T5, T6, T7>
992    where
993        F: FnOnce(T1) -> B,
994    {
995        match self {
996            Self::T1(t1) => Or7::<B, T2, T3, T4, T5, T6, T7>::T1(f(t1)),
997            Self::T2(t2) => Or7::<B, T2, T3, T4, T5, T6, T7>::T2(t2),
998            Self::T3(t3) => Or7::<B, T2, T3, T4, T5, T6, T7>::T3(t3),
999            Self::T4(t4) => Or7::<B, T2, T3, T4, T5, T6, T7>::T4(t4),
1000            Self::T5(t5) => Or7::<B, T2, T3, T4, T5, T6, T7>::T5(t5),
1001            Self::T6(t6) => Or7::<B, T2, T3, T4, T5, T6, T7>::T6(t6),
1002            Self::T7(t7) => Or7::<B, T2, T3, T4, T5, T6, T7>::T7(t7),
1003        }
1004    }
1005
1006    /// Transforms the T2 value of the enum using a provided function,
1007    /// maintaining other types as is.
1008    pub fn map_t2<F, B>(self, f: F) -> Or7<T1, B, T3, T4, T5, T6, T7>
1009    where
1010        F: FnOnce(T2) -> B,
1011    {
1012        match self {
1013            Self::T1(t1) => Or7::<T1, B, T3, T4, T5, T6, T7>::T1(t1),
1014            Self::T2(t2) => Or7::<T1, B, T3, T4, T5, T6, T7>::T2(f(t2)),
1015            Self::T3(t3) => Or7::<T1, B, T3, T4, T5, T6, T7>::T3(t3),
1016            Self::T4(t4) => Or7::<T1, B, T3, T4, T5, T6, T7>::T4(t4),
1017            Self::T5(t5) => Or7::<T1, B, T3, T4, T5, T6, T7>::T5(t5),
1018            Self::T6(t6) => Or7::<T1, B, T3, T4, T5, T6, T7>::T6(t6),
1019            Self::T7(t7) => Or7::<T1, B, T3, T4, T5, T6, T7>::T7(t7),
1020        }
1021    }
1022
1023    /// Transforms the T3 value of the enum using a provided function,
1024    /// maintaining other types as is.
1025    pub fn map_t3<F, B>(self, f: F) -> Or7<T1, T2, B, T4, T5, T6, T7>
1026    where
1027        F: FnOnce(T3) -> B,
1028    {
1029        match self {
1030            Self::T1(t1) => Or7::<T1, T2, B, T4, T5, T6, T7>::T1(t1),
1031            Self::T2(t2) => Or7::<T1, T2, B, T4, T5, T6, T7>::T2(t2),
1032            Self::T3(t3) => Or7::<T1, T2, B, T4, T5, T6, T7>::T3(f(t3)),
1033            Self::T4(t4) => Or7::<T1, T2, B, T4, T5, T6, T7>::T4(t4),
1034            Self::T5(t5) => Or7::<T1, T2, B, T4, T5, T6, T7>::T5(t5),
1035            Self::T6(t6) => Or7::<T1, T2, B, T4, T5, T6, T7>::T6(t6),
1036            Self::T7(t7) => Or7::<T1, T2, B, T4, T5, T6, T7>::T7(t7),
1037        }
1038    }
1039
1040    /// Transforms the T4 value of the enum using a provided function,
1041    /// maintaining other types as is.
1042    pub fn map_t4<F, B>(self, f: F) -> Or7<T1, T2, T3, B, T5, T6, T7>
1043    where
1044        F: FnOnce(T4) -> B,
1045    {
1046        match self {
1047            Self::T1(t1) => Or7::<T1, T2, T3, B, T5, T6, T7>::T1(t1),
1048            Self::T2(t2) => Or7::<T1, T2, T3, B, T5, T6, T7>::T2(t2),
1049            Self::T3(t3) => Or7::<T1, T2, T3, B, T5, T6, T7>::T3(t3),
1050            Self::T4(t4) => Or7::<T1, T2, T3, B, T5, T6, T7>::T4(f(t4)),
1051            Self::T5(t5) => Or7::<T1, T2, T3, B, T5, T6, T7>::T5(t5),
1052            Self::T6(t6) => Or7::<T1, T2, T3, B, T5, T6, T7>::T6(t6),
1053            Self::T7(t7) => Or7::<T1, T2, T3, B, T5, T6, T7>::T7(t7),
1054        }
1055    }
1056
1057    /// Transforms the T5 value of the enum using a provided function,
1058    /// maintaining other types as is.
1059    pub fn map_t5<F, B>(self, f: F) -> Or7<T1, T2, T3, T4, B, T6, T7>
1060    where
1061        F: FnOnce(T5) -> B,
1062    {
1063        match self {
1064            Self::T1(t1) => Or7::<T1, T2, T3, T4, B, T6, T7>::T1(t1),
1065            Self::T2(t2) => Or7::<T1, T2, T3, T4, B, T6, T7>::T2(t2),
1066            Self::T3(t3) => Or7::<T1, T2, T3, T4, B, T6, T7>::T3(t3),
1067            Self::T4(t4) => Or7::<T1, T2, T3, T4, B, T6, T7>::T4(t4),
1068            Self::T5(t5) => Or7::<T1, T2, T3, T4, B, T6, T7>::T5(f(t5)),
1069            Self::T6(t6) => Or7::<T1, T2, T3, T4, B, T6, T7>::T6(t6),
1070            Self::T7(t7) => Or7::<T1, T2, T3, T4, B, T6, T7>::T7(t7),
1071        }
1072    }
1073
1074    /// Transforms the T6 value of the enum using a provided function,
1075    /// maintaining other types as is.
1076    pub fn map_t6<F, B>(self, f: F) -> Or7<T1, T2, T3, T4, T5, B, T7>
1077    where
1078        F: FnOnce(T6) -> B,
1079    {
1080        match self {
1081            Self::T1(t1) => Or7::<T1, T2, T3, T4, T5, B, T7>::T1(t1),
1082            Self::T2(t2) => Or7::<T1, T2, T3, T4, T5, B, T7>::T2(t2),
1083            Self::T3(t3) => Or7::<T1, T2, T3, T4, T5, B, T7>::T3(t3),
1084            Self::T4(t4) => Or7::<T1, T2, T3, T4, T5, B, T7>::T4(t4),
1085            Self::T5(t5) => Or7::<T1, T2, T3, T4, T5, B, T7>::T5(t5),
1086            Self::T6(t6) => Or7::<T1, T2, T3, T4, T5, B, T7>::T6(f(t6)),
1087            Self::T7(t7) => Or7::<T1, T2, T3, T4, T5, B, T7>::T7(t7),
1088        }
1089    }
1090
1091    /// Transforms the T7 value of the enum using a provided function,
1092    /// maintaining other types as is.
1093    pub fn map_t7<F, B>(self, f: F) -> Or7<T1, T2, T3, T4, T5, T6, B>
1094    where
1095        F: FnOnce(T7) -> B,
1096    {
1097        match self {
1098            Self::T1(t1) => Or7::<T1, T2, T3, T4, T5, T6, B>::T1(t1),
1099            Self::T2(t2) => Or7::<T1, T2, T3, T4, T5, T6, B>::T2(t2),
1100            Self::T3(t3) => Or7::<T1, T2, T3, T4, T5, T6, B>::T3(t3),
1101            Self::T4(t4) => Or7::<T1, T2, T3, T4, T5, T6, B>::T4(t4),
1102            Self::T5(t5) => Or7::<T1, T2, T3, T4, T5, T6, B>::T5(t5),
1103            Self::T6(t6) => Or7::<T1, T2, T3, T4, T5, T6, B>::T6(t6),
1104            Self::T7(t7) => Or7::<T1, T2, T3, T4, T5, T6, B>::T7(f(t7)),
1105        }
1106    }
1107
1108    /// Consolidates the `Or7` enum into a single value of type `T`,
1109    /// by applying provided functions.
1110    pub fn fold<T, F0, F1, F2, F3, F4, F5, F6, F7>(
1111        self,
1112        f1: F1,
1113        f2: F2,
1114        f3: F3,
1115        f4: F4,
1116        f5: F5,
1117        f6: F6,
1118        f7: F7,
1119    ) -> T
1120    where
1121        F1: FnOnce(T1) -> T,
1122        F2: FnOnce(T2) -> T,
1123        F3: FnOnce(T3) -> T,
1124        F4: FnOnce(T4) -> T,
1125        F5: FnOnce(T5) -> T,
1126        F6: FnOnce(T6) -> T,
1127        F7: FnOnce(T7) -> T,
1128    {
1129        match self {
1130            Self::T1(t1) => f1(t1),
1131            Self::T2(t2) => f2(t2),
1132            Self::T3(t3) => f3(t3),
1133            Self::T4(t4) => f4(t4),
1134            Self::T5(t5) => f5(t5),
1135            Self::T6(t6) => f6(t6),
1136            Self::T7(t7) => f7(t7),
1137        }
1138    }
1139}
1140
1141/// Extension to `Or7` to check if the enum's type matches a arbitrary type.
1142/// Currently, these functions depend on the rustc intrinsics, and the constraints
1143/// of the intrinsics require that the type must satisfy `'static'`.
1144impl<T1, T2, T3, T4, T5, T6, T7> Or7<T1, T2, T3, T4, T5, T6, T7>
1145where
1146    T1: 'static,
1147    T2: 'static,
1148    T3: 'static,
1149    T4: 'static,
1150    T5: 'static,
1151    T6: 'static,
1152    T7: 'static,
1153{
1154    pub fn is_type<T: 'static>(&self) -> bool {
1155        match self {
1156            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
1157            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
1158            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
1159            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
1160            Self::T5(_) => TypeId::of::<T>() == TypeId::of::<T5>(),
1161            Self::T6(_) => TypeId::of::<T>() == TypeId::of::<T6>(),
1162            Self::T7(_) => TypeId::of::<T>() == TypeId::of::<T7>(),
1163        }
1164    }
1165}
1166
1167/// `Or8` is an enum representing a value that can be either of 8 types, T1 ... T8.
1168pub enum Or8<T1, T2, T3, T4, T5, T6, T7, T8> {
1169    T1(T1),
1170    T2(T2),
1171    T3(T3),
1172    T4(T4),
1173    T5(T5),
1174    T6(T6),
1175    T7(T7),
1176    T8(T8),
1177}
1178
1179impl<T1, T2, T3, T4, T5, T6, T7, T8> Or8<T1, T2, T3, T4, T5, T6, T7, T8> {
1180    /// Returns true if the enum is of type T1.
1181    pub fn is_t1(&self) -> bool {
1182        match self {
1183            Self::T1(_) => true,
1184            _ => false,
1185        }
1186    }
1187
1188    /// Returns true if the enum is of type T2.
1189    pub fn is_t2(&self) -> bool {
1190        match self {
1191            Self::T2(_) => true,
1192            _ => false,
1193        }
1194    }
1195
1196    /// Returns true if the enum is of type T3.
1197    pub fn is_t3(&self) -> bool {
1198        match self {
1199            Self::T3(_) => true,
1200            _ => false,
1201        }
1202    }
1203
1204    /// Returns true if the enum is of type T4.
1205    pub fn is_t4(&self) -> bool {
1206        match self {
1207            Self::T4(_) => true,
1208            _ => false,
1209        }
1210    }
1211
1212    /// Returns true if the enum is of type T5.
1213    pub fn is_t5(&self) -> bool {
1214        match self {
1215            Self::T5(_) => true,
1216            _ => false,
1217        }
1218    }
1219
1220    /// Returns true if the enum is of type T6.
1221    pub fn is_t6(&self) -> bool {
1222        match self {
1223            Self::T6(_) => true,
1224            _ => false,
1225        }
1226    }
1227
1228    /// Returns true if the enum is of type T7.
1229    pub fn is_t7(&self) -> bool {
1230        match self {
1231            Self::T7(_) => true,
1232            _ => false,
1233        }
1234    }
1235
1236    /// Returns true if the enum is of type T8.
1237    pub fn is_t8(&self) -> bool {
1238        match self {
1239            Self::T8(_) => true,
1240            _ => false,
1241        }
1242    }
1243
1244    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
1245    pub fn as_t1(self) -> Option<T1> {
1246        match self {
1247            Self::T1(t1) => Some(t1),
1248            _ => None,
1249        }
1250    }
1251
1252    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
1253    pub fn as_t2(self) -> Option<T2> {
1254        match self {
1255            Self::T2(t2) => Some(t2),
1256            _ => None,
1257        }
1258    }
1259
1260    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
1261    pub fn as_t3(self) -> Option<T3> {
1262        match self {
1263            Self::T3(t3) => Some(t3),
1264            _ => None,
1265        }
1266    }
1267
1268    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
1269    pub fn as_t4(self) -> Option<T4> {
1270        match self {
1271            Self::T4(t4) => Some(t4),
1272            _ => None,
1273        }
1274    }
1275
1276    /// Converts the enum to an Option containing the T5 value, if it is of type T5.
1277    pub fn as_t5(self) -> Option<T5> {
1278        match self {
1279            Self::T5(t5) => Some(t5),
1280            _ => None,
1281        }
1282    }
1283
1284    /// Converts the enum to an Option containing the T6 value, if it is of type T6.
1285    pub fn as_t6(self) -> Option<T6> {
1286        match self {
1287            Self::T6(t6) => Some(t6),
1288            _ => None,
1289        }
1290    }
1291
1292    /// Converts the enum to an Option containing the T7 value, if it is of type T7.
1293    pub fn as_t7(self) -> Option<T7> {
1294        match self {
1295            Self::T7(t7) => Some(t7),
1296            _ => None,
1297        }
1298    }
1299
1300    /// Converts the enum to an Option containing the T8 value, if it is of type T8.
1301    pub fn as_t8(self) -> Option<T8> {
1302        match self {
1303            Self::T8(t8) => Some(t8),
1304            _ => None,
1305        }
1306    }
1307
1308    /// Transforms the T1 value of the enum using a provided function,
1309    /// maintaining other types as is.
1310    pub fn map_t1<F, B>(self, f: F) -> Or8<B, T2, T3, T4, T5, T6, T7, T8>
1311    where
1312        F: FnOnce(T1) -> B,
1313    {
1314        match self {
1315            Self::T1(t1) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T1(f(t1)),
1316            Self::T2(t2) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T2(t2),
1317            Self::T3(t3) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T3(t3),
1318            Self::T4(t4) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T4(t4),
1319            Self::T5(t5) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T5(t5),
1320            Self::T6(t6) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T6(t6),
1321            Self::T7(t7) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T7(t7),
1322            Self::T8(t8) => Or8::<B, T2, T3, T4, T5, T6, T7, T8>::T8(t8),
1323        }
1324    }
1325
1326    /// Transforms the T2 value of the enum using a provided function,
1327    /// maintaining other types as is.
1328    pub fn map_t2<F, B>(self, f: F) -> Or8<T1, B, T3, T4, T5, T6, T7, T8>
1329    where
1330        F: FnOnce(T2) -> B,
1331    {
1332        match self {
1333            Self::T1(t1) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T1(t1),
1334            Self::T2(t2) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T2(f(t2)),
1335            Self::T3(t3) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T3(t3),
1336            Self::T4(t4) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T4(t4),
1337            Self::T5(t5) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T5(t5),
1338            Self::T6(t6) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T6(t6),
1339            Self::T7(t7) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T7(t7),
1340            Self::T8(t8) => Or8::<T1, B, T3, T4, T5, T6, T7, T8>::T8(t8),
1341        }
1342    }
1343
1344    /// Transforms the T3 value of the enum using a provided function,
1345    /// maintaining other types as is.
1346    pub fn map_t3<F, B>(self, f: F) -> Or8<T1, T2, B, T4, T5, T6, T7, T8>
1347    where
1348        F: FnOnce(T3) -> B,
1349    {
1350        match self {
1351            Self::T1(t1) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T1(t1),
1352            Self::T2(t2) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T2(t2),
1353            Self::T3(t3) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T3(f(t3)),
1354            Self::T4(t4) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T4(t4),
1355            Self::T5(t5) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T5(t5),
1356            Self::T6(t6) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T6(t6),
1357            Self::T7(t7) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T7(t7),
1358            Self::T8(t8) => Or8::<T1, T2, B, T4, T5, T6, T7, T8>::T8(t8),
1359        }
1360    }
1361
1362    /// Transforms the T4 value of the enum using a provided function,
1363    /// maintaining other types as is.
1364    pub fn map_t4<F, B>(self, f: F) -> Or8<T1, T2, T3, B, T5, T6, T7, T8>
1365    where
1366        F: FnOnce(T4) -> B,
1367    {
1368        match self {
1369            Self::T1(t1) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T1(t1),
1370            Self::T2(t2) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T2(t2),
1371            Self::T3(t3) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T3(t3),
1372            Self::T4(t4) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T4(f(t4)),
1373            Self::T5(t5) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T5(t5),
1374            Self::T6(t6) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T6(t6),
1375            Self::T7(t7) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T7(t7),
1376            Self::T8(t8) => Or8::<T1, T2, T3, B, T5, T6, T7, T8>::T8(t8),
1377        }
1378    }
1379
1380    /// Transforms the T5 value of the enum using a provided function,
1381    /// maintaining other types as is.
1382    pub fn map_t5<F, B>(self, f: F) -> Or8<T1, T2, T3, T4, B, T6, T7, T8>
1383    where
1384        F: FnOnce(T5) -> B,
1385    {
1386        match self {
1387            Self::T1(t1) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T1(t1),
1388            Self::T2(t2) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T2(t2),
1389            Self::T3(t3) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T3(t3),
1390            Self::T4(t4) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T4(t4),
1391            Self::T5(t5) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T5(f(t5)),
1392            Self::T6(t6) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T6(t6),
1393            Self::T7(t7) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T7(t7),
1394            Self::T8(t8) => Or8::<T1, T2, T3, T4, B, T6, T7, T8>::T8(t8),
1395        }
1396    }
1397
1398    /// Transforms the T6 value of the enum using a provided function,
1399    /// maintaining other types as is.
1400    pub fn map_t6<F, B>(self, f: F) -> Or8<T1, T2, T3, T4, T5, B, T7, T8>
1401    where
1402        F: FnOnce(T6) -> B,
1403    {
1404        match self {
1405            Self::T1(t1) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T1(t1),
1406            Self::T2(t2) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T2(t2),
1407            Self::T3(t3) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T3(t3),
1408            Self::T4(t4) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T4(t4),
1409            Self::T5(t5) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T5(t5),
1410            Self::T6(t6) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T6(f(t6)),
1411            Self::T7(t7) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T7(t7),
1412            Self::T8(t8) => Or8::<T1, T2, T3, T4, T5, B, T7, T8>::T8(t8),
1413        }
1414    }
1415
1416    /// Transforms the T7 value of the enum using a provided function,
1417    /// maintaining other types as is.
1418    pub fn map_t7<F, B>(self, f: F) -> Or8<T1, T2, T3, T4, T5, T6, B, T8>
1419    where
1420        F: FnOnce(T7) -> B,
1421    {
1422        match self {
1423            Self::T1(t1) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T1(t1),
1424            Self::T2(t2) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T2(t2),
1425            Self::T3(t3) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T3(t3),
1426            Self::T4(t4) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T4(t4),
1427            Self::T5(t5) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T5(t5),
1428            Self::T6(t6) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T6(t6),
1429            Self::T7(t7) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T7(f(t7)),
1430            Self::T8(t8) => Or8::<T1, T2, T3, T4, T5, T6, B, T8>::T8(t8),
1431        }
1432    }
1433
1434    /// Transforms the T8 value of the enum using a provided function,
1435    /// maintaining other types as is.
1436    pub fn map_t8<F, B>(self, f: F) -> Or8<T1, T2, T3, T4, T5, T6, T7, B>
1437    where
1438        F: FnOnce(T8) -> B,
1439    {
1440        match self {
1441            Self::T1(t1) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T1(t1),
1442            Self::T2(t2) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T2(t2),
1443            Self::T3(t3) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T3(t3),
1444            Self::T4(t4) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T4(t4),
1445            Self::T5(t5) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T5(t5),
1446            Self::T6(t6) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T6(t6),
1447            Self::T7(t7) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T7(t7),
1448            Self::T8(t8) => Or8::<T1, T2, T3, T4, T5, T6, T7, B>::T8(f(t8)),
1449        }
1450    }
1451
1452    /// Consolidates the `Or8` enum into a single value of type `T`,
1453    /// by applying provided functions.
1454    pub fn fold<T, F0, F1, F2, F3, F4, F5, F6, F7, F8>(
1455        self,
1456        f1: F1,
1457        f2: F2,
1458        f3: F3,
1459        f4: F4,
1460        f5: F5,
1461        f6: F6,
1462        f7: F7,
1463        f8: F8,
1464    ) -> T
1465    where
1466        F1: FnOnce(T1) -> T,
1467        F2: FnOnce(T2) -> T,
1468        F3: FnOnce(T3) -> T,
1469        F4: FnOnce(T4) -> T,
1470        F5: FnOnce(T5) -> T,
1471        F6: FnOnce(T6) -> T,
1472        F7: FnOnce(T7) -> T,
1473        F8: FnOnce(T8) -> T,
1474    {
1475        match self {
1476            Self::T1(t1) => f1(t1),
1477            Self::T2(t2) => f2(t2),
1478            Self::T3(t3) => f3(t3),
1479            Self::T4(t4) => f4(t4),
1480            Self::T5(t5) => f5(t5),
1481            Self::T6(t6) => f6(t6),
1482            Self::T7(t7) => f7(t7),
1483            Self::T8(t8) => f8(t8),
1484        }
1485    }
1486}
1487
1488/// Extension to `Or8` to check if the enum's type matches a arbitrary type.
1489/// Currently, these functions depend on the rustc intrinsics, and the constraints
1490/// of the intrinsics require that the type must satisfy `'static'`.
1491impl<T1, T2, T3, T4, T5, T6, T7, T8> Or8<T1, T2, T3, T4, T5, T6, T7, T8>
1492where
1493    T1: 'static,
1494    T2: 'static,
1495    T3: 'static,
1496    T4: 'static,
1497    T5: 'static,
1498    T6: 'static,
1499    T7: 'static,
1500    T8: 'static,
1501{
1502    pub fn is_type<T: 'static>(&self) -> bool {
1503        match self {
1504            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
1505            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
1506            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
1507            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
1508            Self::T5(_) => TypeId::of::<T>() == TypeId::of::<T5>(),
1509            Self::T6(_) => TypeId::of::<T>() == TypeId::of::<T6>(),
1510            Self::T7(_) => TypeId::of::<T>() == TypeId::of::<T7>(),
1511            Self::T8(_) => TypeId::of::<T>() == TypeId::of::<T8>(),
1512        }
1513    }
1514}
1515
1516/// `Or9` is an enum representing a value that can be either of 9 types, T1 ... T9.
1517pub enum Or9<T1, T2, T3, T4, T5, T6, T7, T8, T9> {
1518    T1(T1),
1519    T2(T2),
1520    T3(T3),
1521    T4(T4),
1522    T5(T5),
1523    T6(T6),
1524    T7(T7),
1525    T8(T8),
1526    T9(T9),
1527}
1528
1529impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> Or9<T1, T2, T3, T4, T5, T6, T7, T8, T9> {
1530    /// Returns true if the enum is of type T1.
1531    pub fn is_t1(&self) -> bool {
1532        match self {
1533            Self::T1(_) => true,
1534            _ => false,
1535        }
1536    }
1537
1538    /// Returns true if the enum is of type T2.
1539    pub fn is_t2(&self) -> bool {
1540        match self {
1541            Self::T2(_) => true,
1542            _ => false,
1543        }
1544    }
1545
1546    /// Returns true if the enum is of type T3.
1547    pub fn is_t3(&self) -> bool {
1548        match self {
1549            Self::T3(_) => true,
1550            _ => false,
1551        }
1552    }
1553
1554    /// Returns true if the enum is of type T4.
1555    pub fn is_t4(&self) -> bool {
1556        match self {
1557            Self::T4(_) => true,
1558            _ => false,
1559        }
1560    }
1561
1562    /// Returns true if the enum is of type T5.
1563    pub fn is_t5(&self) -> bool {
1564        match self {
1565            Self::T5(_) => true,
1566            _ => false,
1567        }
1568    }
1569
1570    /// Returns true if the enum is of type T6.
1571    pub fn is_t6(&self) -> bool {
1572        match self {
1573            Self::T6(_) => true,
1574            _ => false,
1575        }
1576    }
1577
1578    /// Returns true if the enum is of type T7.
1579    pub fn is_t7(&self) -> bool {
1580        match self {
1581            Self::T7(_) => true,
1582            _ => false,
1583        }
1584    }
1585
1586    /// Returns true if the enum is of type T8.
1587    pub fn is_t8(&self) -> bool {
1588        match self {
1589            Self::T8(_) => true,
1590            _ => false,
1591        }
1592    }
1593
1594    /// Returns true if the enum is of type T9.
1595    pub fn is_t9(&self) -> bool {
1596        match self {
1597            Self::T9(_) => true,
1598            _ => false,
1599        }
1600    }
1601
1602    /// Converts the enum to an Option containing the T1 value, if it is of type T1.
1603    pub fn as_t1(self) -> Option<T1> {
1604        match self {
1605            Self::T1(t1) => Some(t1),
1606            _ => None,
1607        }
1608    }
1609
1610    /// Converts the enum to an Option containing the T2 value, if it is of type T2.
1611    pub fn as_t2(self) -> Option<T2> {
1612        match self {
1613            Self::T2(t2) => Some(t2),
1614            _ => None,
1615        }
1616    }
1617
1618    /// Converts the enum to an Option containing the T3 value, if it is of type T3.
1619    pub fn as_t3(self) -> Option<T3> {
1620        match self {
1621            Self::T3(t3) => Some(t3),
1622            _ => None,
1623        }
1624    }
1625
1626    /// Converts the enum to an Option containing the T4 value, if it is of type T4.
1627    pub fn as_t4(self) -> Option<T4> {
1628        match self {
1629            Self::T4(t4) => Some(t4),
1630            _ => None,
1631        }
1632    }
1633
1634    /// Converts the enum to an Option containing the T5 value, if it is of type T5.
1635    pub fn as_t5(self) -> Option<T5> {
1636        match self {
1637            Self::T5(t5) => Some(t5),
1638            _ => None,
1639        }
1640    }
1641
1642    /// Converts the enum to an Option containing the T6 value, if it is of type T6.
1643    pub fn as_t6(self) -> Option<T6> {
1644        match self {
1645            Self::T6(t6) => Some(t6),
1646            _ => None,
1647        }
1648    }
1649
1650    /// Converts the enum to an Option containing the T7 value, if it is of type T7.
1651    pub fn as_t7(self) -> Option<T7> {
1652        match self {
1653            Self::T7(t7) => Some(t7),
1654            _ => None,
1655        }
1656    }
1657
1658    /// Converts the enum to an Option containing the T8 value, if it is of type T8.
1659    pub fn as_t8(self) -> Option<T8> {
1660        match self {
1661            Self::T8(t8) => Some(t8),
1662            _ => None,
1663        }
1664    }
1665
1666    /// Converts the enum to an Option containing the T9 value, if it is of type T9.
1667    pub fn as_t9(self) -> Option<T9> {
1668        match self {
1669            Self::T9(t9) => Some(t9),
1670            _ => None,
1671        }
1672    }
1673
1674    /// Transforms the T1 value of the enum using a provided function,
1675    /// maintaining other types as is.
1676    pub fn map_t1<F, B>(self, f: F) -> Or9<B, T2, T3, T4, T5, T6, T7, T8, T9>
1677    where
1678        F: FnOnce(T1) -> B,
1679    {
1680        match self {
1681            Self::T1(t1) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T1(f(t1)),
1682            Self::T2(t2) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T2(t2),
1683            Self::T3(t3) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T3(t3),
1684            Self::T4(t4) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T4(t4),
1685            Self::T5(t5) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T5(t5),
1686            Self::T6(t6) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T6(t6),
1687            Self::T7(t7) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T7(t7),
1688            Self::T8(t8) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T8(t8),
1689            Self::T9(t9) => Or9::<B, T2, T3, T4, T5, T6, T7, T8, T9>::T9(t9),
1690        }
1691    }
1692
1693    /// Transforms the T2 value of the enum using a provided function,
1694    /// maintaining other types as is.
1695    pub fn map_t2<F, B>(self, f: F) -> Or9<T1, B, T3, T4, T5, T6, T7, T8, T9>
1696    where
1697        F: FnOnce(T2) -> B,
1698    {
1699        match self {
1700            Self::T1(t1) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T1(t1),
1701            Self::T2(t2) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T2(f(t2)),
1702            Self::T3(t3) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T3(t3),
1703            Self::T4(t4) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T4(t4),
1704            Self::T5(t5) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T5(t5),
1705            Self::T6(t6) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T6(t6),
1706            Self::T7(t7) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T7(t7),
1707            Self::T8(t8) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T8(t8),
1708            Self::T9(t9) => Or9::<T1, B, T3, T4, T5, T6, T7, T8, T9>::T9(t9),
1709        }
1710    }
1711
1712    /// Transforms the T3 value of the enum using a provided function,
1713    /// maintaining other types as is.
1714    pub fn map_t3<F, B>(self, f: F) -> Or9<T1, T2, B, T4, T5, T6, T7, T8, T9>
1715    where
1716        F: FnOnce(T3) -> B,
1717    {
1718        match self {
1719            Self::T1(t1) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T1(t1),
1720            Self::T2(t2) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T2(t2),
1721            Self::T3(t3) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T3(f(t3)),
1722            Self::T4(t4) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T4(t4),
1723            Self::T5(t5) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T5(t5),
1724            Self::T6(t6) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T6(t6),
1725            Self::T7(t7) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T7(t7),
1726            Self::T8(t8) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T8(t8),
1727            Self::T9(t9) => Or9::<T1, T2, B, T4, T5, T6, T7, T8, T9>::T9(t9),
1728        }
1729    }
1730
1731    /// Transforms the T4 value of the enum using a provided function,
1732    /// maintaining other types as is.
1733    pub fn map_t4<F, B>(self, f: F) -> Or9<T1, T2, T3, B, T5, T6, T7, T8, T9>
1734    where
1735        F: FnOnce(T4) -> B,
1736    {
1737        match self {
1738            Self::T1(t1) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T1(t1),
1739            Self::T2(t2) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T2(t2),
1740            Self::T3(t3) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T3(t3),
1741            Self::T4(t4) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T4(f(t4)),
1742            Self::T5(t5) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T5(t5),
1743            Self::T6(t6) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T6(t6),
1744            Self::T7(t7) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T7(t7),
1745            Self::T8(t8) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T8(t8),
1746            Self::T9(t9) => Or9::<T1, T2, T3, B, T5, T6, T7, T8, T9>::T9(t9),
1747        }
1748    }
1749
1750    /// Transforms the T5 value of the enum using a provided function,
1751    /// maintaining other types as is.
1752    pub fn map_t5<F, B>(self, f: F) -> Or9<T1, T2, T3, T4, B, T6, T7, T8, T9>
1753    where
1754        F: FnOnce(T5) -> B,
1755    {
1756        match self {
1757            Self::T1(t1) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T1(t1),
1758            Self::T2(t2) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T2(t2),
1759            Self::T3(t3) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T3(t3),
1760            Self::T4(t4) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T4(t4),
1761            Self::T5(t5) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T5(f(t5)),
1762            Self::T6(t6) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T6(t6),
1763            Self::T7(t7) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T7(t7),
1764            Self::T8(t8) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T8(t8),
1765            Self::T9(t9) => Or9::<T1, T2, T3, T4, B, T6, T7, T8, T9>::T9(t9),
1766        }
1767    }
1768
1769    /// Transforms the T6 value of the enum using a provided function,
1770    /// maintaining other types as is.
1771    pub fn map_t6<F, B>(self, f: F) -> Or9<T1, T2, T3, T4, T5, B, T7, T8, T9>
1772    where
1773        F: FnOnce(T6) -> B,
1774    {
1775        match self {
1776            Self::T1(t1) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T1(t1),
1777            Self::T2(t2) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T2(t2),
1778            Self::T3(t3) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T3(t3),
1779            Self::T4(t4) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T4(t4),
1780            Self::T5(t5) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T5(t5),
1781            Self::T6(t6) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T6(f(t6)),
1782            Self::T7(t7) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T7(t7),
1783            Self::T8(t8) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T8(t8),
1784            Self::T9(t9) => Or9::<T1, T2, T3, T4, T5, B, T7, T8, T9>::T9(t9),
1785        }
1786    }
1787
1788    /// Transforms the T7 value of the enum using a provided function,
1789    /// maintaining other types as is.
1790    pub fn map_t7<F, B>(self, f: F) -> Or9<T1, T2, T3, T4, T5, T6, B, T8, T9>
1791    where
1792        F: FnOnce(T7) -> B,
1793    {
1794        match self {
1795            Self::T1(t1) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T1(t1),
1796            Self::T2(t2) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T2(t2),
1797            Self::T3(t3) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T3(t3),
1798            Self::T4(t4) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T4(t4),
1799            Self::T5(t5) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T5(t5),
1800            Self::T6(t6) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T6(t6),
1801            Self::T7(t7) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T7(f(t7)),
1802            Self::T8(t8) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T8(t8),
1803            Self::T9(t9) => Or9::<T1, T2, T3, T4, T5, T6, B, T8, T9>::T9(t9),
1804        }
1805    }
1806
1807    /// Transforms the T8 value of the enum using a provided function,
1808    /// maintaining other types as is.
1809    pub fn map_t8<F, B>(self, f: F) -> Or9<T1, T2, T3, T4, T5, T6, T7, B, T9>
1810    where
1811        F: FnOnce(T8) -> B,
1812    {
1813        match self {
1814            Self::T1(t1) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T1(t1),
1815            Self::T2(t2) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T2(t2),
1816            Self::T3(t3) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T3(t3),
1817            Self::T4(t4) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T4(t4),
1818            Self::T5(t5) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T5(t5),
1819            Self::T6(t6) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T6(t6),
1820            Self::T7(t7) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T7(t7),
1821            Self::T8(t8) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T8(f(t8)),
1822            Self::T9(t9) => Or9::<T1, T2, T3, T4, T5, T6, T7, B, T9>::T9(t9),
1823        }
1824    }
1825
1826    /// Transforms the T9 value of the enum using a provided function,
1827    /// maintaining other types as is.
1828    pub fn map_t9<F, B>(self, f: F) -> Or9<T1, T2, T3, T4, T5, T6, T7, T8, B>
1829    where
1830        F: FnOnce(T9) -> B,
1831    {
1832        match self {
1833            Self::T1(t1) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T1(t1),
1834            Self::T2(t2) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T2(t2),
1835            Self::T3(t3) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T3(t3),
1836            Self::T4(t4) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T4(t4),
1837            Self::T5(t5) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T5(t5),
1838            Self::T6(t6) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T6(t6),
1839            Self::T7(t7) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T7(t7),
1840            Self::T8(t8) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T8(t8),
1841            Self::T9(t9) => Or9::<T1, T2, T3, T4, T5, T6, T7, T8, B>::T9(f(t9)),
1842        }
1843    }
1844
1845    /// Consolidates the `Or9` enum into a single value of type `T`,
1846    /// by applying provided functions.
1847    pub fn fold<T, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9>(
1848        self,
1849        f1: F1,
1850        f2: F2,
1851        f3: F3,
1852        f4: F4,
1853        f5: F5,
1854        f6: F6,
1855        f7: F7,
1856        f8: F8,
1857        f9: F9,
1858    ) -> T
1859    where
1860        F1: FnOnce(T1) -> T,
1861        F2: FnOnce(T2) -> T,
1862        F3: FnOnce(T3) -> T,
1863        F4: FnOnce(T4) -> T,
1864        F5: FnOnce(T5) -> T,
1865        F6: FnOnce(T6) -> T,
1866        F7: FnOnce(T7) -> T,
1867        F8: FnOnce(T8) -> T,
1868        F9: FnOnce(T9) -> T,
1869    {
1870        match self {
1871            Self::T1(t1) => f1(t1),
1872            Self::T2(t2) => f2(t2),
1873            Self::T3(t3) => f3(t3),
1874            Self::T4(t4) => f4(t4),
1875            Self::T5(t5) => f5(t5),
1876            Self::T6(t6) => f6(t6),
1877            Self::T7(t7) => f7(t7),
1878            Self::T8(t8) => f8(t8),
1879            Self::T9(t9) => f9(t9),
1880        }
1881    }
1882}
1883
1884/// Extension to `Or9` to check if the enum's type matches a arbitrary type.
1885/// Currently, these functions depend on the rustc intrinsics, and the constraints
1886/// of the intrinsics require that the type must satisfy `'static'`.
1887impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> Or9<T1, T2, T3, T4, T5, T6, T7, T8, T9>
1888where
1889    T1: 'static,
1890    T2: 'static,
1891    T3: 'static,
1892    T4: 'static,
1893    T5: 'static,
1894    T6: 'static,
1895    T7: 'static,
1896    T8: 'static,
1897    T9: 'static,
1898{
1899    pub fn is_type<T: 'static>(&self) -> bool {
1900        match self {
1901            Self::T1(_) => TypeId::of::<T>() == TypeId::of::<T1>(),
1902            Self::T2(_) => TypeId::of::<T>() == TypeId::of::<T2>(),
1903            Self::T3(_) => TypeId::of::<T>() == TypeId::of::<T3>(),
1904            Self::T4(_) => TypeId::of::<T>() == TypeId::of::<T4>(),
1905            Self::T5(_) => TypeId::of::<T>() == TypeId::of::<T5>(),
1906            Self::T6(_) => TypeId::of::<T>() == TypeId::of::<T6>(),
1907            Self::T7(_) => TypeId::of::<T>() == TypeId::of::<T7>(),
1908            Self::T8(_) => TypeId::of::<T>() == TypeId::of::<T8>(),
1909            Self::T9(_) => TypeId::of::<T>() == TypeId::of::<T9>(),
1910        }
1911    }
1912}