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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// Macro to "derive" ( not really a derive macro ) SystemParam for a struct.
#[macro_export]
macro_rules! impl_system_param {
    (
        $( #[$m:meta] )*
        pub struct $t:ident<'a> {
            $(
                $( #[$attrs:meta] )*
                $f_name:ident: $f_ty:ty
            ),*
            $(,)?
        }
    ) => {
        $( #[$m] )*
        pub struct $t<'a> {
            $(
                $( #[$attrs] )*
                pub $f_name: $f_ty
            ),*
        }

        impl<'a> SystemParam for $t<'a> {
            type State = (
                $(
                    <$f_ty as SystemParam>::State
                ),*
            );
            type Param<'p> = $t<'p>;

            fn get_state(world: &World) -> Self::State {
                (
                    $(
                        <$f_ty as SystemParam>::get_state(world)
                    ),*
                )
            }

            fn borrow<'s>(world: &'s World, state: &'s mut Self::State) -> Self::Param<'s> {
                let (
                    $(
                        $f_name
                    ),*
                ) = state;
                let (
                    $(
                        $f_name
                    ),*
                ) = (
                    $(
                        <$f_ty as SystemParam>::borrow(world, $f_name)
                    ),*
                );

                Self::Param {
                    $(
                        $f_name
                    ),*
                }
            }
        }
    };
}