@@ -140,11 +140,32 @@ pub fn derive_reflect(input: TokenStream) -> TokenStream {
140
140
141
141
/// Derives the `FromReflect` trait.
142
142
///
143
- /// This macro supports the following field attributes:
144
- /// * `#[reflect(ignore)]`: Ignores the field. This requires the field to implement [`Default`].
145
- /// * `#[reflect(default)]`: If the field's value cannot be read, uses its [`Default`] implementation.
146
- /// * `#[reflect(default = "some_func")]`: If the field's value cannot be read, uses the function with the given name.
143
+ /// # Field Attributes
144
+ ///
145
+ /// ## `#[reflect(ignore)]`
146
+ ///
147
+ /// The `#[reflect(ignore)]` attribute is shared with the [`Reflect` derive macro] and has much of the same
148
+ /// functionality in that it marks a field to be ignored by the reflection API.
149
+ ///
150
+ /// The only major difference is that using it with this derive requires that the field implements [`Default`].
151
+ /// Without this requirement, there would be no way for `FromReflect` to automatically construct missing fields
152
+ /// that have been ignored.
147
153
///
154
+ /// ## `#[reflect(default)]`
155
+ ///
156
+ /// If a field cannot be read, this attribute specifies a default value to be used in its place.
157
+ ///
158
+ /// By default, this attribute denotes that the field's type implements [`Default`].
159
+ /// However, it can also take in a path string to a user-defined function that will return the default value.
160
+ /// This takes the form: `#[reflect(default = "path::to::my_function)]` where `my_function` is a parameterless
161
+ /// function that must return some default value for the type.
162
+ ///
163
+ /// Specifying a custom default can be used to give different fields their own specialized defaults,
164
+ /// or to remove the `Default` requirement on fields marked with `#[reflect(ignore)]`.
165
+ /// Additionally, either form of this attribute can be used to fill in fields that are simply missing,
166
+ /// such as when converting a partially-constructed dynamic type to a concrete one.
167
+ ///
168
+ /// [`Reflect` derive macro]: Reflect
148
169
#[ proc_macro_derive( FromReflect , attributes( reflect) ) ]
149
170
pub fn derive_from_reflect ( input : TokenStream ) -> TokenStream {
150
171
let ast = parse_macro_input ! ( input as DeriveInput ) ;
0 commit comments