@@ -25,8 +25,27 @@ use std::{
25
25
///
26
26
/// # Derive
27
27
///
28
- /// This trait can be derived with the [`derive@super::SystemParam`] macro. The only requirement
29
- /// is that every struct field must also implement `SystemParam`.
28
+ /// This trait can be derived with the [`derive@super::SystemParam`] macro.
29
+ /// This macro only works if each field on the derived struct implements [`SystemParam`].
30
+ /// Note: There are additional requirements on the field types.
31
+ /// See the *Generic `SystemParam`s* section for details and workarounds of the probable
32
+ /// cause if this derive causes an error to be emitted.
33
+ ///
34
+ ///
35
+ /// The struct for which `SystemParam` is derived must (currently) have exactly
36
+ /// two lifetime parameters.
37
+ /// The first is the lifetime of the world, and the second the lifetime
38
+ /// of the parameter's state.
39
+ ///
40
+ /// ## Attributes
41
+ ///
42
+ /// `#[system_param(ignore)]`:
43
+ /// Can be added to any field in the struct. Fields decorated with this attribute
44
+ /// will created with the default value upon realisation.
45
+ /// This is most useful for `PhantomData` fields, to ensure that the required lifetimes are
46
+ /// used, as shown in the example.
47
+ ///
48
+ /// # Example
30
49
///
31
50
/// ```
32
51
/// # use bevy_ecs::prelude::*;
@@ -46,6 +65,30 @@ use std::{
46
65
///
47
66
/// # bevy_ecs::system::assert_is_system(my_system);
48
67
/// ```
68
+ ///
69
+ /// # Generic `SystemParam`s
70
+ ///
71
+ /// When using the derive macro, you may see an error in the form of:
72
+ ///
73
+ /// ```text
74
+ /// expected ... [ParamType]
75
+ /// found associated type `<<[ParamType] as SystemParam>::Fetch as SystemParamFetch<'_, '_>>::Item`
76
+ /// ```
77
+ /// where `[ParamType]` is the type of one of your fields.
78
+ /// To solve this error, you can wrap the field of type `[ParamType]` with [`StaticSystemParam`]
79
+ /// (i.e. `StaticSystemParam<[ParamType]>`).
80
+ ///
81
+ /// ## Details
82
+ ///
83
+ /// The derive macro requires that the [`SystemParam`] implementation of
84
+ /// each field `F`'s [`Fetch`](`SystemParam::Fetch`)'s [`Item`](`SystemParamFetch::Item`) is itself `F`
85
+ /// (ignoring lifetimes for simplicity).
86
+ /// This assumption is due to type inference reasons, so that the derived [`SystemParam`] can be
87
+ /// used as an argument to a function system.
88
+ /// If the compiler cannot validate this property for `[ParamType]`, it will error in the form shown above.
89
+ ///
90
+ /// This will most commonly occur when working with `SystemParam`s generically, as the requirement
91
+ /// has not been proven to the compiler.
49
92
pub trait SystemParam : Sized {
50
93
type Fetch : for < ' w , ' s > SystemParamFetch < ' w , ' s > ;
51
94
}
0 commit comments