From 9226356b7b54c4c5b036b6fee00bba376245c5f3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 24 Jul 2026 22:32:21 +0200 Subject: feat(engine-ecs): add traversal query term --- engine-ecs/src/tuple.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'engine-ecs/src/tuple.rs') diff --git a/engine-ecs/src/tuple.rs b/engine-ecs/src/tuple.rs index 15e1719..a2073b1 100644 --- a/engine-ecs/src/tuple.rs +++ b/engine-ecs/src/tuple.rs @@ -1,4 +1,5 @@ -use std::{any::TypeId, convert::Infallible}; +use std::any::TypeId; +use std::convert::Infallible; use paste::paste; use seq_macro::seq; @@ -55,6 +56,32 @@ pub trait ReduceElement type Return; } +pub trait ElementConcat +{ + type Output; + + fn add_to(self, acc: Acc) -> Self::Output; +} + +impl ElementConcat for Elem +where + Acc: Tuple, +{ + type Output = Acc::WithElementAtEnd; + + fn add_to(self, acc: Acc) -> Self::Output + { + acc.with_elem(self) + } +} + +pub trait Concat +{ + type Output; + + fn concat(self, left: Left) -> Self::Output; +} + macro_rules! tuple_reduce_elem_tuple { (overflow) => { () @@ -67,6 +94,18 @@ macro_rules! tuple_reduce_elem_tuple { }; } +macro_rules! tuple_concat_elem_ouput { + (overflow) => { + Left + }; + + ($index: tt) => { + paste! { + []::Output + } + }; +} + macro_rules! elem_type_by_index { (overflow) => { () @@ -148,6 +187,31 @@ macro_rules! impl_tuple_traits { } } + paste! { + impl Concat for (#(Elem~I,)*) + where + Left: Tuple, + #( + Elem~I: ElementConcat< + sub!(I - 1, tuple_concat_elem_ouput), + >, + )* + { + type Output = sub!($cnt - 1, tuple_concat_elem_ouput); + + fn concat(self, left: Left) -> Self::Output + { + let out = left; + + #( + let out = self.I.add_to(out); + )* + + out + } + } + } + impl<#(Elem~I: 'static,)*> WithAllElemLtStatic for (#(Elem~I,)*) { fn get_mut(&mut self, index: usize) -> Option<&mut Element> -- cgit v1.2.3-18-g5258