async_ecs/misc/
split.rs

1pub trait Split {
2    type Left;
3    type Right;
4
5    fn split(self) -> (Self::Left, Self::Right);
6}
7
8macro_rules! for_each_prefix (
9    ($m:ident, [$(($acc:tt),)*], []) => {
10        $m!($($acc,)*);
11    };
12    ($m:ident, [$(($acc:tt),)*], [($arg0:tt), $(($arg:tt),)*]) => {
13        $m!($($acc,)*);
14        for_each_prefix!($m, [$(($acc),)* ($arg0),], [$(($arg),)*]);
15    };
16);
17
18macro_rules! split_impl (
19    ($(($a:ident, $b:ident),)*) => (
20        impl<$($a,)* $($b,)*> Split for ($($a,)* $($b,)*) {
21            type Left = ($($a,)*);
22            type Right = ($($b,)*);
23
24            #[allow(non_snake_case)]
25            fn split(self) -> (Self::Left, Self::Right) {
26                match self {
27                    ($($a,)* $($b,)*) => (($($a,)*), ($($b,)*))
28                }
29            }
30        }
31
32        impl<$($a,)* $($b,)* TLast> Split for ($($a,)* $($b,)* TLast,) {
33            type Left = ($($a,)*);
34            type Right = ($($b,)* TLast,);
35
36            #[allow(non_snake_case)]
37            fn split(self) -> (Self::Left, Self::Right) {
38                match self {
39                    ($($a,)* $($b,)* t_last,) => (($($a,)*), ($($b,)* t_last,))
40                }
41            }
42        }
43    );
44);
45
46for_each_prefix! {
47    split_impl,
48    [],
49    [((T0, T1)), ((T2, T3)), ((T4, T5)), ((T6, T7)), ((T8, T9)), ((T10, T11)), ((T12, T13)), ((T14, T15)),]
50}