From f954bee2a90de66c138ae1168e4e32ef0df1b2eb Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 20 Sep 2026 20:40:00 +0200 Subject: feat(engine-ecs): make bundles nestable --- engine-ecs/src/bundle.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'engine-ecs/src/bundle.rs') diff --git a/engine-ecs/src/bundle.rs b/engine-ecs/src/bundle.rs index 89e0cc4..4c13599 100644 --- a/engine-ecs/src/bundle.rs +++ b/engine-ecs/src/bundle.rs @@ -1,34 +1,26 @@ use seq_macro::seq; -use crate::component::{IntoParts, Parts}; -use crate::util::Array; +use crate::component::{IntoParts as IntoComponentParts, Parts as ComponentParts}; -pub trait Bundle +pub trait Bundle: 'static { - type PartsArray: Array; - - fn cnt(&self) -> usize; - - fn into_parts_array(self) -> Self::PartsArray; + fn iter_component_parts(self) -> impl Iterator; } macro_rules! gen_tuple_impls { ($c: tt) => { seq!(I in 0..$c { - impl<#(IntoCompParts~I: IntoParts,)*> Bundle for (#(IntoCompParts~I,)*) + impl<#(Bundle~I: Bundle,)*> Bundle for (#(Bundle~I,)*) { - type PartsArray = [Parts; $c]; - - fn cnt(&self) -> usize + fn iter_component_parts(self) -> impl Iterator { - $c - } + let parts = [].into_iter(); - fn into_parts_array(self) -> Self::PartsArray - { - [#({ - self.I.into_parts() - },)*] + #( + let parts = parts.chain(self.I.iter_component_parts()); + )* + + parts } } }); @@ -38,3 +30,11 @@ macro_rules! gen_tuple_impls { seq!(C in 0..17 { gen_tuple_impls!(C); }); + +impl Bundle for T +{ + fn iter_component_parts(self) -> impl Iterator + { + [self.into_parts()].into_iter() + } +} -- cgit v1.2.3-18-g5258