diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-20 20:40:00 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-20 20:40:00 +0200 |
| commit | f954bee2a90de66c138ae1168e4e32ef0df1b2eb (patch) | |
| tree | 277dd9bfdc947c54a8220ee04f4eeadf4483340b /engine-ecs/src/bundle.rs | |
| parent | a228e48b345d142fdb0c17b5c39ea7685dd4c67b (diff) | |
Diffstat (limited to 'engine-ecs/src/bundle.rs')
| -rw-r--r-- | engine-ecs/src/bundle.rs | 38 |
1 files changed, 19 insertions, 19 deletions
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<Parts>; - - fn cnt(&self) -> usize; - - fn into_parts_array(self) -> Self::PartsArray; + fn iter_component_parts(self) -> impl Iterator<Item = ComponentParts>; } 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<Item = ComponentParts> { - $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<T: IntoComponentParts + 'static> Bundle for T +{ + fn iter_component_parts(self) -> impl Iterator<Item = ComponentParts> + { + [self.into_parts()].into_iter() + } +} |
