1
- use crate :: container_attributes:: ReflectTraits ;
1
+ use crate :: container_attributes:: { FromReflectAttrs , ReflectTraits } ;
2
2
use crate :: field_attributes:: { parse_field_attrs, ReflectFieldAttr } ;
3
3
use crate :: utility:: members_to_serialization_denylist;
4
4
use bit_set:: BitSet ;
5
5
use quote:: quote;
6
6
7
- use crate :: { utility, REFLECT_ATTRIBUTE_NAME , REFLECT_VALUE_ATTRIBUTE_NAME } ;
7
+ use crate :: {
8
+ utility, FROM_REFLECT_ATTRIBUTE_NAME , REFLECT_ATTRIBUTE_NAME , REFLECT_VALUE_ATTRIBUTE_NAME ,
9
+ } ;
8
10
use syn:: punctuated:: Punctuated ;
9
11
use syn:: spanned:: Spanned ;
10
12
use syn:: { Data , DeriveInput , Field , Fields , Generics , Ident , Meta , Path , Token , Variant } ;
@@ -33,6 +35,8 @@ pub(crate) enum ReflectDerive<'a> {
33
35
pub ( crate ) struct ReflectMeta < ' a > {
34
36
/// The registered traits for this type.
35
37
traits : ReflectTraits ,
38
+ /// The `FromReflect` attributes for this type.
39
+ from_reflect : FromReflectAttrs ,
36
40
/// The name of this type.
37
41
type_name : & ' a Ident ,
38
42
/// The generics defined on this type.
@@ -129,6 +133,7 @@ enum ReflectMode {
129
133
impl < ' a > ReflectDerive < ' a > {
130
134
pub fn from_input ( input : & ' a DeriveInput ) -> Result < Self , syn:: Error > {
131
135
let mut traits = ReflectTraits :: default ( ) ;
136
+ let mut from_reflect = FromReflectAttrs :: default ( ) ;
132
137
// Should indicate whether `#[reflect_value]` was used
133
138
let mut reflect_mode = None ;
134
139
@@ -161,6 +166,9 @@ impl<'a> ReflectDerive<'a> {
161
166
let new_traits = ReflectTraits :: from_nested_metas ( & meta_list. nested ) ?;
162
167
traits = traits. merge ( new_traits) ?;
163
168
}
169
+ Meta :: List ( meta_list) if meta_list. path . is_ident ( FROM_REFLECT_ATTRIBUTE_NAME ) => {
170
+ from_reflect = FromReflectAttrs :: from_nested_metas ( & meta_list. nested ) ?;
171
+ }
164
172
Meta :: Path ( path) if path. is_ident ( REFLECT_VALUE_ATTRIBUTE_NAME ) => {
165
173
if !matches ! ( reflect_mode, None | Some ( ReflectMode :: Value ) ) {
166
174
return Err ( syn:: Error :: new (
@@ -181,7 +189,7 @@ impl<'a> ReflectDerive<'a> {
181
189
}
182
190
}
183
191
184
- let meta = ReflectMeta :: new ( & input. ident , & input. generics , traits) ;
192
+ let meta = ReflectMeta :: new ( & input. ident , & input. generics , traits, from_reflect ) ;
185
193
186
194
#[ cfg( feature = "documentation" ) ]
187
195
let meta = meta. with_docs ( doc) ;
@@ -278,9 +286,15 @@ impl<'a> ReflectDerive<'a> {
278
286
}
279
287
280
288
impl < ' a > ReflectMeta < ' a > {
281
- pub fn new ( type_name : & ' a Ident , generics : & ' a Generics , traits : ReflectTraits ) -> Self {
289
+ pub fn new (
290
+ type_name : & ' a Ident ,
291
+ generics : & ' a Generics ,
292
+ traits : ReflectTraits ,
293
+ from_reflect : FromReflectAttrs ,
294
+ ) -> Self {
282
295
Self {
283
296
traits,
297
+ from_reflect,
284
298
type_name,
285
299
generics,
286
300
bevy_reflect_path : utility:: get_bevy_reflect_path ( ) ,
@@ -300,6 +314,12 @@ impl<'a> ReflectMeta<'a> {
300
314
& self . traits
301
315
}
302
316
317
+ /// The `FromReflect` attributes on this type.
318
+ #[ allow( clippy:: wrong_self_convention) ]
319
+ pub fn from_reflect ( & self ) -> & FromReflectAttrs {
320
+ & self . from_reflect
321
+ }
322
+
303
323
/// The name of this struct.
304
324
pub fn type_name ( & self ) -> & ' a Ident {
305
325
self . type_name
0 commit comments