From 8adf787bca7744344b83dace7997031b07785a25 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 6 Jun 2024 22:27:03 +0200 Subject: refactor(ecs): rename tuple filter to tuple reduce --- ecs/src/tuple.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'ecs/src/tuple.rs') diff --git a/ecs/src/tuple.rs b/ecs/src/tuple.rs index bb27f58..5ed8993 100644 --- a/ecs/src/tuple.rs +++ b/ecs/src/tuple.rs @@ -25,17 +25,16 @@ pub trait WithOptionElements fn take(&mut self) -> TakeOptionElementResult; } -/// Used to filter the elements of a tuple type. -pub trait Filter +/// 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 { type Out; } -/// Used by implementations of [`Filter`] to know whether this element should be -/// filtered out or not. -pub trait FilterElement +pub trait ReduceElement { - type Tuple; + type Return; } /// The result of trying to [`take`] a element from a implementation of @@ -54,24 +53,23 @@ pub enum TakeOptionElementResult AlreadyTaken, } -/// Zero-sized struct excluded when filtering the elements of a tuple type using -/// implementations of [`Filter`]. +/// Zero-sized struct implementing [`ReduceElement`] and just returns the accumulator. #[derive(Debug, Clone, Copy)] -pub struct FilterExclude; +pub struct ReduceNoOp; -impl FilterElement for FilterExclude +impl ReduceElement for ReduceNoOp { - type Tuple = Tup; + type Return = Accumulator; } -macro_rules! tuple_filter_elem_tuple { +macro_rules! tuple_reduce_elem_tuple { (overflow) => { () }; ($index: tt) => { paste! { - []::Tuple + []::Return } }; } @@ -121,11 +119,11 @@ macro_rules! impl_tuple_traits { } paste! { - impl<#(Elem~I,)*> Filter for (#(Elem~I,)*) + impl<#(Elem~I,)*> Reduce for (#(Elem~I,)*) where - #(Elem~I: FilterElement,)* + #(Elem~I: ReduceElement,)* { - type Out = sub!($cnt - 1, tuple_filter_elem_tuple); + type Out = sub!($cnt - 1, tuple_reduce_elem_tuple); } } }); -- cgit v1.2.3-18-g5258