Skip to main content

pebble/ecs/
system_set.rs

1use crate::ecs::system::{IntoSystem, System};
2
3/// Converts a tuple of systems into a `Vec<Box<dyn System>>` so they can be
4/// registered together with [`App::add_systems`](crate::app::App::add_systems).
5pub trait IntoSystemSet<M> {
6    fn into_system_set(self) -> Vec<Box<dyn System>>;
7}
8
9macro_rules! impl_into_system_set {
10    ($(($sys:ident, $marker:ident)),+) => {
11        impl<$($sys, $marker),+> IntoSystemSet<($($marker,)+)> for ($($sys,)+)
12        where
13            $($sys: IntoSystem<$marker> + 'static,)+
14        {
15            fn into_system_set(self) -> Vec<Box<dyn System>> {
16                #[allow(non_snake_case)]
17                let ($($sys,)+) = self;
18                vec![$(Box::new($sys.into_system()) as Box<dyn System>),+]
19            }
20        }
21    };
22}
23
24impl_into_system_set!((A, MA));
25impl_into_system_set!((A, MA), (B, MB));
26impl_into_system_set!((A, MA), (B, MB), (C, MC));
27impl_into_system_set!((A, MA), (B, MB), (C, MC), (D, MD));
28impl_into_system_set!((A, MA), (B, MB), (C, MC), (D, MD), (E, ME));
29impl_into_system_set!((A, MA), (B, MB), (C, MC), (D, MD), (E, ME), (G, MG));
30impl_into_system_set!(
31    (A, MA),
32    (B, MB),
33    (C, MC),
34    (D, MD),
35    (E, ME),
36    (G, MG),
37    (H, MH)
38);