diff options
Diffstat (limited to 'ecs/src/tuple.rs')
-rw-r--r-- | ecs/src/tuple.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/ecs/src/tuple.rs b/ecs/src/tuple.rs index 5ed8993..682c11d 100644 --- a/ecs/src/tuple.rs +++ b/ecs/src/tuple.rs @@ -27,12 +27,12 @@ pub trait WithOptionElements /// Using the type system, reduces the elements of a tuple to a single one. Each element /// determines itself how it is handled. -pub trait Reduce +pub trait Reduce<Operation> { type Out; } -pub trait ReduceElement<Accumulator> +pub trait ReduceElement<Accumulator, Operation> { type Return; } @@ -53,15 +53,6 @@ pub enum TakeOptionElementResult<Element> AlreadyTaken, } -/// Zero-sized struct implementing [`ReduceElement`] and just returns the accumulator. -#[derive(Debug, Clone, Copy)] -pub struct ReduceNoOp; - -impl<Accumulator> ReduceElement<Accumulator> for ReduceNoOp -{ - type Return = Accumulator; -} - macro_rules! tuple_reduce_elem_tuple { (overflow) => { () @@ -77,7 +68,8 @@ macro_rules! tuple_reduce_elem_tuple { macro_rules! impl_tuple_traits { ($cnt: tt) => { seq!(I in 0..$cnt { - impl<OtherElem, #(Elem~I,)*> With<OtherElem> for (#(Elem~I,)*) { + impl<OtherElem, #(Elem~I,)*> With<OtherElem> for (#(Elem~I,)*) + { type With = (#(Elem~I,)* OtherElem,); } @@ -119,9 +111,13 @@ macro_rules! impl_tuple_traits { } paste! { - impl<#(Elem~I,)*> Reduce for (#(Elem~I,)*) + impl<Operation, #(Elem~I,)*> Reduce<Operation> for (#(Elem~I,)*) where - #(Elem~I: ReduceElement<sub!(I - 1, tuple_reduce_elem_tuple)>,)* + #( + Elem~I: ReduceElement< + sub!(I - 1, tuple_reduce_elem_tuple), Operation + >, + )* { type Out = sub!($cnt - 1, tuple_reduce_elem_tuple); } |