diff options
Diffstat (limited to 'engine-ecs/src/tuple.rs')
| -rw-r--r-- | engine-ecs/src/tuple.rs | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/engine-ecs/src/tuple.rs b/engine-ecs/src/tuple.rs index 15e1719..a2073b1 100644 --- a/engine-ecs/src/tuple.rs +++ b/engine-ecs/src/tuple.rs @@ -1,4 +1,5 @@ -use std::{any::TypeId, convert::Infallible}; +use std::any::TypeId; +use std::convert::Infallible; use paste::paste; use seq_macro::seq; @@ -55,6 +56,32 @@ pub trait ReduceElement<Accumulator, Operation> type Return; } +pub trait ElementConcat<Acc> +{ + type Output; + + fn add_to(self, acc: Acc) -> Self::Output; +} + +impl<Elem, Acc> ElementConcat<Acc> for Elem +where + Acc: Tuple, +{ + type Output = Acc::WithElementAtEnd<Elem>; + + fn add_to(self, acc: Acc) -> Self::Output + { + acc.with_elem(self) + } +} + +pub trait Concat<Left> +{ + type Output; + + fn concat(self, left: Left) -> Self::Output; +} + macro_rules! tuple_reduce_elem_tuple { (overflow) => { () @@ -67,6 +94,18 @@ macro_rules! tuple_reduce_elem_tuple { }; } +macro_rules! tuple_concat_elem_ouput { + (overflow) => { + Left + }; + + ($index: tt) => { + paste! { + [<Elem $index>]::Output + } + }; +} + macro_rules! elem_type_by_index { (overflow) => { () @@ -148,6 +187,31 @@ macro_rules! impl_tuple_traits { } } + paste! { + impl<Left, #(Elem~I,)*> Concat<Left> for (#(Elem~I,)*) + where + Left: Tuple, + #( + Elem~I: ElementConcat< + sub!(I - 1, tuple_concat_elem_ouput), + >, + )* + { + type Output = sub!($cnt - 1, tuple_concat_elem_ouput); + + fn concat(self, left: Left) -> Self::Output + { + let out = left; + + #( + let out = self.I.add_to(out); + )* + + out + } + } + } + impl<#(Elem~I: 'static,)*> WithAllElemLtStatic for (#(Elem~I,)*) { fn get_mut<Element: 'static>(&mut self, index: usize) -> Option<&mut Element> |
