summaryrefslogtreecommitdiff
path: root/engine-ecs/src/bundle.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src/bundle.rs')
-rw-r--r--engine-ecs/src/bundle.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/engine-ecs/src/bundle.rs b/engine-ecs/src/bundle.rs
new file mode 100644
index 0000000..4c13599
--- /dev/null
+++ b/engine-ecs/src/bundle.rs
@@ -0,0 +1,40 @@
+use seq_macro::seq;
+
+use crate::component::{IntoParts as IntoComponentParts, Parts as ComponentParts};
+
+pub trait Bundle: 'static
+{
+ fn iter_component_parts(self) -> impl Iterator<Item = ComponentParts>;
+}
+
+macro_rules! gen_tuple_impls {
+ ($c: tt) => {
+ seq!(I in 0..$c {
+ impl<#(Bundle~I: Bundle,)*> Bundle for (#(Bundle~I,)*)
+ {
+ fn iter_component_parts(self) -> impl Iterator<Item = ComponentParts>
+ {
+ let parts = [].into_iter();
+
+ #(
+ let parts = parts.chain(self.I.iter_component_parts());
+ )*
+
+ parts
+ }
+ }
+ });
+ };
+}
+
+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()
+ }
+}