diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-07 19:55:47 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-07 19:55:47 +0200 |
commit | bef61b765de52d14a52c3df86f8b3766846be272 (patch) | |
tree | b032d9c440844231e8623e8a0e83b5b95caab4f8 /ecs/src/tuple.rs | |
parent | 8adf787bca7744344b83dace7997031b07785a25 (diff) |
refactor(ecs): make tuple reduce operation more generic
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); } |