diff options
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() + } +} |
