@@ -7,7 +7,7 @@ use quote::quote;
7
7
use crate :: { utility, REFLECT_ATTRIBUTE_NAME , REFLECT_VALUE_ATTRIBUTE_NAME } ;
8
8
use syn:: punctuated:: Punctuated ;
9
9
use syn:: spanned:: Spanned ;
10
- use syn:: { Data , DeriveInput , Field , Fields , Generics , Ident , Meta , Path , Token , Variant } ;
10
+ use syn:: { Data , DeriveInput , Field , Fields , Generics , Ident , Meta , Path , Token , Type , Variant } ;
11
11
12
12
pub ( crate ) enum ReflectDerive < ' a > {
13
13
Struct ( ReflectStruct < ' a > ) ,
@@ -323,6 +323,7 @@ impl<'a> ReflectMeta<'a> {
323
323
self . traits . idents ( ) ,
324
324
self . generics ,
325
325
None ,
326
+ None :: < std:: iter:: Empty < & Type > > ,
326
327
)
327
328
}
328
329
@@ -347,22 +348,7 @@ impl<'a> ReflectStruct<'a> {
347
348
& self . serialization_denylist
348
349
}
349
350
350
- /// Returns the `GetTypeRegistration` impl as a `TokenStream`.
351
- ///
352
- /// Returns a specific implementation for structs and this method should be preffered over the generic [`get_type_registration`](crate::ReflectMeta) method
353
- pub fn get_type_registration ( & self ) -> proc_macro2:: TokenStream {
354
- let reflect_path = self . meta . bevy_reflect_path ( ) ;
355
-
356
- crate :: registration:: impl_get_type_registration (
357
- self . meta . type_name ( ) ,
358
- reflect_path,
359
- self . meta . traits ( ) . idents ( ) ,
360
- self . meta . generics ( ) ,
361
- Some ( & self . serialization_denylist ) ,
362
- )
363
- }
364
-
365
- /// Get a collection of types which are exposed to the reflection API
351
+ /// Get a collection of types which are exposed to the reflection API.
366
352
pub fn active_types ( & self ) -> Vec < syn:: Type > {
367
353
self . fields
368
354
. iter ( )
@@ -371,25 +357,39 @@ impl<'a> ReflectStruct<'a> {
371
357
. collect :: < Vec < _ > > ( )
372
358
}
373
359
374
- /// Get an iterator of fields which are exposed to the reflection API
360
+ /// Get an iterator of fields which are exposed to the reflection API.
375
361
pub fn active_fields ( & self ) -> impl Iterator < Item = & StructField < ' a > > {
376
- self . fields
362
+ self . fields ( )
377
363
. iter ( )
378
364
. filter ( move |field| field. attrs . ignore . is_active ( ) )
379
365
}
380
366
381
- /// Get an iterator of fields which are ignored by the reflection API
367
+ /// Get an iterator of fields which are ignored by the reflection API.
382
368
pub fn ignored_fields ( & self ) -> impl Iterator < Item = & StructField < ' a > > {
383
- self . fields
369
+ self . fields ( )
384
370
. iter ( )
385
371
. filter ( move |field| field. attrs . ignore . is_ignored ( ) )
386
372
}
387
373
388
374
/// The complete set of fields in this struct.
389
- #[ allow( dead_code) ]
390
375
pub fn fields ( & self ) -> & [ StructField < ' a > ] {
391
376
& self . fields
392
377
}
378
+
379
+ /// Returns the `GetTypeRegistration` impl as a `TokenStream`.
380
+ ///
381
+ /// Returns a specific implementation for structs.
382
+ /// This method should be preferred over the generic [`get_type_registration`](crate::ReflectMeta) method.
383
+ pub fn get_type_registration ( & self ) -> proc_macro2:: TokenStream {
384
+ crate :: registration:: impl_get_type_registration (
385
+ self . meta . type_name ,
386
+ & self . meta . bevy_reflect_path ,
387
+ self . meta . traits . idents ( ) ,
388
+ self . meta . generics ,
389
+ Some ( & self . serialization_denylist ) ,
390
+ Some ( self . active_types ( ) . iter ( ) ) ,
391
+ )
392
+ }
393
393
}
394
394
395
395
impl < ' a > ReflectEnum < ' a > {
@@ -410,4 +410,38 @@ impl<'a> ReflectEnum<'a> {
410
410
pub fn variants ( & self ) -> & [ EnumVariant < ' a > ] {
411
411
& self . variants
412
412
}
413
+
414
+ /// Returns the `GetTypeRegistration` impl as a `TokenStream`.
415
+ pub fn get_type_registration ( & self ) -> proc_macro2:: TokenStream {
416
+ crate :: registration:: impl_get_type_registration (
417
+ self . meta . type_name ,
418
+ & self . meta . bevy_reflect_path ,
419
+ self . meta . traits . idents ( ) ,
420
+ self . meta . generics ,
421
+ None ,
422
+ Some (
423
+ self . variants ( )
424
+ . iter ( )
425
+ . flat_map ( |variant| variant. active_fields ( ) )
426
+ . map ( |field| & field. data . ty ) ,
427
+ ) ,
428
+ )
429
+ }
430
+ }
431
+
432
+ impl < ' a > EnumVariant < ' a > {
433
+ /// The complete set of fields in this variant.
434
+ pub fn fields ( & self ) -> & [ StructField < ' a > ] {
435
+ match & self . fields {
436
+ EnumVariantFields :: Named ( fields) | EnumVariantFields :: Unnamed ( fields) => fields,
437
+ EnumVariantFields :: Unit => & [ ] ,
438
+ }
439
+ }
440
+
441
+ /// Get an iterator of fields which are exposed to the reflection API
442
+ pub fn active_fields ( & self ) -> impl Iterator < Item = & StructField < ' a > > {
443
+ self . fields ( )
444
+ . iter ( )
445
+ . filter ( |field| !field. attrs . ignore . is_ignored ( ) )
446
+ }
413
447
}
0 commit comments