From bef61b765de52d14a52c3df86f8b3766846be272 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 7 Jun 2024 19:55:47 +0200 Subject: refactor(ecs): make tuple reduce operation more generic --- ecs/src/tuple.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'ecs/src/tuple.rs') 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 { type Out; } -pub trait ReduceElement +pub trait ReduceElement { type Return; } @@ -53,15 +53,6 @@ pub enum TakeOptionElementResult AlreadyTaken, } -/// Zero-sized struct implementing [`ReduceElement`] and just returns the accumulator. -#[derive(Debug, Clone, Copy)] -pub struct ReduceNoOp; - -impl ReduceElement 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 With for (#(Elem~I,)*) { + impl With 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 Reduce for (#(Elem~I,)*) where - #(Elem~I: ReduceElement,)* + #( + Elem~I: ReduceElement< + sub!(I - 1, tuple_reduce_elem_tuple), Operation + >, + )* { type Out = sub!($cnt - 1, tuple_reduce_elem_tuple); } -- cgit v1.2.3-18-g5258