@@ -47,6 +47,8 @@ pub(crate) struct ReflectMeta<'a> {
4747 attrs : ContainerAttributes ,
4848 /// The path to this type.
4949 type_path : ReflectTypePath < ' a > ,
50+ /// The optional remote type to use instead of the actual type.
51+ remote_ty : Option < RemoteType < ' a > > ,
5052 /// A cached instance of the path to the `bevy_reflect` crate.
5153 bevy_reflect_path : Path ,
5254 /// The documentation for this type, if any
@@ -71,7 +73,6 @@ pub(crate) struct ReflectStruct<'a> {
7173 meta : ReflectMeta < ' a > ,
7274 serialization_data : Option < SerializationDataDef > ,
7375 fields : Vec < StructField < ' a > > ,
74- remote_ty : Option < RemoteType < ' a > > ,
7576}
7677
7778/// Enum data used by derive macros for `Reflect` and `FromReflect`.
@@ -90,7 +91,6 @@ pub(crate) struct ReflectStruct<'a> {
9091pub ( crate ) struct ReflectEnum < ' a > {
9192 meta : ReflectMeta < ' a > ,
9293 variants : Vec < EnumVariant < ' a > > ,
93- remote_ty : Option < RemoteType < ' a > > ,
9494}
9595
9696/// Represents a field on a struct or tuple struct.
@@ -331,7 +331,6 @@ impl<'a> ReflectDerive<'a> {
331331 meta,
332332 serialization_data : SerializationDataDef :: new ( & fields) ?,
333333 fields,
334- remote_ty : None ,
335334 } ;
336335
337336 match data. fields {
@@ -343,11 +342,7 @@ impl<'a> ReflectDerive<'a> {
343342 Data :: Enum ( data) => {
344343 let variants = Self :: collect_enum_variants ( & data. variants ) ?;
345344
346- let reflect_enum = ReflectEnum {
347- meta,
348- variants,
349- remote_ty : None ,
350- } ;
345+ let reflect_enum = ReflectEnum { meta, variants } ;
351346 Ok ( Self :: Enum ( reflect_enum) )
352347 }
353348 Data :: Union ( ..) => Err ( syn:: Error :: new (
@@ -365,23 +360,25 @@ impl<'a> ReflectDerive<'a> {
365360 pub fn set_remote ( & mut self , remote_ty : Option < RemoteType < ' a > > ) {
366361 match self {
367362 Self :: Struct ( data) | Self :: TupleStruct ( data) | Self :: UnitStruct ( data) => {
368- data. remote_ty = remote_ty;
363+ data. meta . remote_ty = remote_ty;
369364 }
370365 Self :: Enum ( data) => {
371- data. remote_ty = remote_ty;
366+ data. meta . remote_ty = remote_ty;
367+ }
368+ Self :: Value ( meta) => {
369+ meta. remote_ty = remote_ty;
372370 }
373- _ => panic ! ( "cannot create a reflected value type for a remote type" ) ,
374371 }
375372 }
376373
377374 /// Get the remote type path, if any.
378375 pub fn remote_ty ( & self ) -> Option < RemoteType > {
379376 match self {
380377 Self :: Struct ( data) | Self :: TupleStruct ( data) | Self :: UnitStruct ( data) => {
381- data. remote_ty ( )
378+ data. meta . remote_ty ( )
382379 }
383- Self :: Enum ( data) => data. remote_ty ( ) ,
384- Self :: Value ( _ ) => None ,
380+ Self :: Enum ( data) => data. meta . remote_ty ( ) ,
381+ Self :: Value ( meta ) => meta . remote_ty ( ) ,
385382 }
386383 }
387384
@@ -475,6 +472,7 @@ impl<'a> ReflectMeta<'a> {
475472 Self {
476473 attrs,
477474 type_path,
475+ remote_ty : None ,
478476 bevy_reflect_path : utility:: get_bevy_reflect_path ( ) ,
479477 #[ cfg( feature = "documentation" ) ]
480478 docs : Default :: default ( ) ,
@@ -508,6 +506,16 @@ impl<'a> ReflectMeta<'a> {
508506 & self . type_path
509507 }
510508
509+ /// Get the remote type path, if any.
510+ pub fn remote_ty ( & self ) -> Option < RemoteType > {
511+ self . remote_ty
512+ }
513+
514+ /// Whether this reflected type represents a remote type or not.
515+ pub fn is_remote_wrapper ( & self ) -> bool {
516+ self . remote_ty . is_some ( )
517+ }
518+
511519 /// The cached `bevy_reflect` path.
512520 pub fn bevy_reflect_path ( & self ) -> & Path {
513521 & self . bevy_reflect_path
@@ -595,17 +603,6 @@ impl<'a> ReflectStruct<'a> {
595603 self . serialization_data . as_ref ( )
596604 }
597605
598- /// Whether this reflected struct represents a remote type or not.
599- pub fn is_remote_wrapper ( & self ) -> bool {
600- self . remote_ty . is_some ( )
601- }
602-
603- #[ allow( dead_code) ]
604- /// Get the remote type path, if any.
605- pub fn remote_ty ( & self ) -> Option < RemoteType < ' a > > {
606- self . remote_ty
607- }
608-
609606 /// Returns the `GetTypeRegistration` impl as a `TokenStream`.
610607 ///
611608 /// Returns a specific implementation for structs and this method should be preferred over the generic [`get_type_registration`](ReflectMeta) method
@@ -705,22 +702,12 @@ impl<'a> ReflectEnum<'a> {
705702 & self . meta
706703 }
707704
708- /// Whether this reflected enum represents a remote type or not.
709- pub fn is_remote_wrapper ( & self ) -> bool {
710- self . remote_ty . is_some ( )
711- }
712-
713- #[ allow( dead_code) ]
714- /// Get the remote type path, if any.
715- pub fn remote_ty ( & self ) -> Option < RemoteType < ' a > > {
716- self . remote_ty
717- }
718-
719705 /// Returns the given ident as a qualified unit variant of this enum.
720706 ///
721707 /// This takes into account the remote type, if any.
722708 pub fn get_unit ( & self , variant : & Ident ) -> proc_macro2:: TokenStream {
723709 let name = self
710+ . meta
724711 . remote_ty
725712 . map ( |path| match path. as_expr_path ( ) {
726713 Ok ( path) => path. to_token_stream ( ) ,
0 commit comments