summaryrefslogtreecommitdiff
path: root/engine-ecs/src/bundle.rs
blob: 4c13599d56a6f2a7d5be415de2c8cc0d0221e978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()
    }
}