wecs_core/system/
system_param.rs

1use crate::world::{UnsafeWorldCell, World};
2
3pub trait SystemParam: Sized {
4    type Item<'world>: SystemParam;
5
6    fn get_param<'world>(world: UnsafeWorldCell<'world>) -> Self::Item<'world>;
7}
8
9pub type SystemParamItem<'w, P> = <P as SystemParam>::Item<'w>;
10
11impl SystemParam for () {
12    type Item<'world> = ();
13
14    fn get_param<'world>(_world: UnsafeWorldCell<'world>) -> Self::Item<'world> {
15        ()
16    }
17}
18
19// impl<T> SystemParam for T
20// where
21//     T: SystemParam,
22// {
23//     type Item<'world> = T::Item<'world>;
24
25//     fn get_param<'world>(_world: UnsafeWorldCell<'world>) -> Self::Item<'world> {
26//         ()
27//     }
28// }
29
30macro_rules! impl_sp_for {
31    ( $($n:ident),* ) => {
32        #[allow(non_snake_case)]
33        impl<$($n,)*> SystemParam for ($($n,)*)
34        where $($n: SystemParam,)* {
35            type Item<'world> = ($($n::Item<'world>,)*);
36
37            fn get_param<'world>(world: UnsafeWorldCell<'world>) -> Self::Item<'world> {
38                $(let $n = $n::get_param(world);)*
39
40                ($($n,)*)
41            }
42        }
43    };
44}
45
46impl_sp_for!(T1);
47impl_sp_for!(T1, T2);
48impl_sp_for!(T1, T2, T3);
49impl_sp_for!(T1, T2, T3, T4);
50impl_sp_for!(T1, T2, T3, T4, T5);
51impl_sp_for!(T1, T2, T3, T4, T5, T6);
52impl_sp_for!(T1, T2, T3, T4, T5, T6, T7);
53impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8);
54impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9);
55impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
56impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11);
57impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12);
58impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13);
59impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14);
60impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15);
61impl_sp_for!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16);