File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,18 @@ fn setup(type_registry: Res<AppTypeRegistry>) {
59
59
// You can also get the &dyn PartialReflect value of a field like this
60
60
let field = value. field ( "a" ) . unwrap ( ) ;
61
61
62
- // you can downcast Reflect values like this:
63
- assert_eq ! ( * field. try_downcast_ref:: <usize >( ) . unwrap( ) , 2 ) ;
62
+ // For concrete-type based operations like downcasting, we need a `&dyn Reflect`,
63
+ // which can be retrieved from a `&dyn PartialReflect` using `as_full`.
64
+ // `as_full` returns an `Option<&dyn Reflect>` since some types like `DynamicStruct`
65
+ // implement `PartialReflect` but not `Reflect`.
66
+ // There are also `as_full_mut` and `into_full` methods for conversion
67
+ // into `&mut dyn Reflect` and `Box<dyn Reflect>` respectively.
68
+ let full_reflect: & dyn Reflect = field. as_full ( ) . unwrap ( ) ;
64
69
65
- // DynamicStruct also implements the `Struct` and `Reflect` traits.
70
+ // You can downcast Reflect values like this:
71
+ assert_eq ! ( * full_reflect. downcast_ref:: <usize >( ) . unwrap( ) , 2 ) ;
72
+
73
+ // DynamicStruct also implements the `Struct` and `PartialReflect` traits.
66
74
let mut patch = DynamicStruct :: default ( ) ;
67
75
patch. insert ( "a" , 4usize ) ;
68
76
You can’t perform that action at this time.
0 commit comments