type_sets/
set.rs

1use std::marker::PhantomData;
2
3/// Marker struct to act as a set of elements.
4///
5/// Use the [`macro@Set`] macro instead of typing this out directly.
6///
7/// The inner type `T` is one of the [`sets`](crate::sets), and indicates the
8/// elements in this set.
9/// - `Set![]` == `Set<dyn Zero>`
10/// - `Set![u32]` == `Set<dyn One<u32>>`
11/// - `Set![u32, u64]` == `Set<dyn Two<u32, u64>>`
12pub struct Set<T: ?Sized>(PhantomData<fn() -> T>);
13
14/// Create a [`struct@Set`] from a list of types.
15///
16/// Example:
17/// - `Set![]` == `Set<dyn Zero>`
18/// - `Set![u32]` == `Set<dyn One<u32>>`
19/// - `Set![u32, u64]` == `Set<dyn Two<u32, u64>>`
20/// 
21/// This macro works for up to 12 types.
22#[macro_export]
23macro_rules! Set {
24    ($(,)?) => {
25        $crate::Set<dyn $crate::sets::Zero>
26    };
27    ($t1:ty $(,)?) => {
28        $crate::Set<dyn $crate::sets::One<$t1>>
29    };
30    ($t1:ty, $t2:ty $(,)?) => {
31        $crate::Set<dyn $crate::sets::Two<$t1, $t2>>
32    };
33    ($t1:ty, $t2:ty, $t3:ty $(,)?) => {
34        $crate::Set<dyn $crate::sets::Three<$t1, $t2, $t3>>
35    };
36    ($t1:ty, $t2:ty, $t3:ty, $t4:ty $(,)?) => {
37        $crate::Set<dyn $crate::sets::Four<$t1, $t2, $t3, $t4>>
38    };
39    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty $(,)?) => {
40        $crate::Set<dyn $crate::sets::Five<$t1, $t2, $t3, $t4, $t5>>
41    };
42    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty $(,)?) => {
43        $crate::Set<dyn $crate::sets::Six<$t1, $t2, $t3, $t4, $t5, $t6>>
44    };
45    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty $(,)?) => {
46        $crate::Set<dyn $crate::sets::Seven<$t1, $t2, $t3, $t4, $t5, $t6, $t7>>
47    };
48    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty $(,)?) => {
49        $crate::Set<dyn $crate::sets::Eight<$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8>>
50    };
51    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty $(,)?) => {
52        $crate::Set<dyn $crate::sets::Nine<$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9>>
53    };
54    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty $(,)?) => {
55        $crate::Set<dyn $crate::sets::Ten<$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10>>
56    };
57    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty $(,)?) => {
58        $crate::Set<dyn $crate::sets::Eleven<$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11>>
59    };
60    ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty $(,)?) => {
61        $crate::Set<dyn $crate::sets::Twelve<$t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12>>
62    };
63}