diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-06 22:27:03 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-06 22:27:03 +0200 |
commit | 8adf787bca7744344b83dace7997031b07785a25 (patch) | |
tree | 4b510178e39593f08e548972f493e1856f703a15 /ecs/src/tuple.rs | |
parent | cb1ff29c8c7fa77bbb4e532eaa7e45df717a58ef (diff) |
refactor(ecs): rename tuple filter to tuple reduce
Diffstat (limited to 'ecs/src/tuple.rs')
-rw-r--r-- | ecs/src/tuple.rs | 30 |
1 files changed, 14 insertions, 16 deletions
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<Element: 'static>(&mut self) -> TakeOptionElementResult<Element>; } -/// 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<Tup> +pub trait ReduceElement<Accumulator> { - type Tuple; + type Return; } /// The result of trying to [`take`] a element from a implementation of @@ -54,24 +53,23 @@ pub enum TakeOptionElementResult<Element> 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<Tup> FilterElement<Tup> for FilterExclude +impl<Accumulator> ReduceElement<Accumulator> for ReduceNoOp { - type Tuple = Tup; + type Return = Accumulator; } -macro_rules! tuple_filter_elem_tuple { +macro_rules! tuple_reduce_elem_tuple { (overflow) => { () }; ($index: tt) => { paste! { - [<Elem $index>]::Tuple + [<Elem $index>]::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<sub!(I - 1, tuple_filter_elem_tuple)>,)* + #(Elem~I: ReduceElement<sub!(I - 1, tuple_reduce_elem_tuple)>,)* { - type Out = sub!($cnt - 1, tuple_filter_elem_tuple); + type Out = sub!($cnt - 1, tuple_reduce_elem_tuple); } } }); |