Skip to main content

hecs_schedule/
macros.rs

1#![allow(non_snake_case)]
2
3#[macro_export]
4/// Expands a tuple
5macro_rules! expand {
6    ($macro:ident, $letter:tt) => {
7        //$macro!($letter);
8    };
9    ($macro:ident, [] => [$($acc:tt),*]) => {
10        $macro!($($acc),*);
11    };
12    ($macro:ident, [$letter:tt] => [$($acc:tt),*]) => {
13        $macro!($($acc),*);
14        $crate::expand!($macro, [] => [$($acc),*,$letter ]);
15    };
16    ($macro:ident, $letter:tt, $($tail:tt),*) => {
17        $crate::expand!($macro, [$($tail),*] => [$letter]);
18    };
19    ($macro:ident, [$letter:tt, $($tail:tt),*] => [$($acc:tt),*]) => {
20        $macro!($($acc),*);
21        $crate::expand!($macro, [$($tail),*] => [$($acc),*, $letter]);
22    };
23}
24
25#[macro_export]
26/// Execute macro for each kind of tuple
27macro_rules! impl_for_tuples {
28    ($macro:ident) => {
29        $crate::expand!($macro, L, K, J, I, H, G, F, E, D, C, B, A);
30    };
31}
32
33#[macro_export]
34/// Execute macro for each kind of tuple
35macro_rules! impl_for_tuples_idx {
36    ($macro:ident) => {
37        $crate::expand!($macro,
38         [ 0 => L ],
39         [ 1 => K ],
40         [ 2  => J ],
41         [ 3  => I ],
42         [ 4  => H ],
43         [ 5  => G ],
44         [ 6  => F ],
45         [ 7  => E ],
46         [ 8  => D ],
47         [ 9  => C ],
48         [ 10  => B ],
49         [ 11  => A ]);
50    };
51}
52
53#[macro_export]
54/// Return size of tuple
55macro_rules! count {
56    () => {0usize};
57    ($head:ident $($tail:ident)*) => {1usize + count!($($tail)*)};
58}