gravitron_ecs/
entity.rs

1use gravitron_ecs_macros::all_tuples;
2
3use crate::components::Component;
4
5pub trait IntoEntity {
6  fn into_entity(self) -> Vec<Box<dyn Component>>;
7}
8
9impl<F0: Component + 'static> IntoEntity for F0 {
10  #[inline]
11  fn into_entity(self) -> Vec<Box<dyn Component>> {
12    vec![Box::new(self)]
13  }
14}
15
16macro_rules! impl_into_entity {
17  ($($params:ident),*) => {
18    #[allow(non_snake_case)]
19    impl<$($params : Component + 'static),*> IntoEntity for ($($params ,)*) {
20      #[inline]
21      fn into_entity(self) -> Vec<Box<dyn Component>> {
22        let ($($params ,)*) = self;
23        vec![$(Box::new($params)),*]
24      }
25    }
26  };
27}
28
29all_tuples!(impl_into_entity, 1, 16, F);