File tree Expand file tree Collapse file tree 5 files changed +11
-14
lines changed Expand file tree Collapse file tree 5 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -132,8 +132,8 @@ let reflect_value: Box<dyn Reflect> = Box::new(MyType {
132132 value : " Hello" . to_string (),
133133});
134134
135- // This means we no longer have direct access to MyType or it methods. We can only call Reflect methods on reflect_value.
136- // What if we want to call `do_thing` on our type? We could downcast using reflect_value.get ::<MyType>(), but what if we
135+ // This means we no longer have direct access to MyType or its methods. We can only call Reflect methods on reflect_value.
136+ // What if we want to call `do_thing` on our type? We could downcast using reflect_value.downcast_ref ::<MyType>(), but what if we
137137// don't know the type at compile time?
138138
139139// Normally in rust we would be out of luck at this point. Lets use our new reflection powers to do something cool!
@@ -146,7 +146,7 @@ let reflect_do_thing = type_registry
146146 . get_type_data :: <ReflectDoThing >(reflect_value . type_id ())
147147 . unwrap ();
148148
149- // We can use this generated type to convert our `&dyn Reflect` reference to an `&dyn DoThing` reference
149+ // We can use this generated type to convert our `&dyn Reflect` reference to a `&dyn DoThing` reference
150150let my_trait : & dyn DoThing = reflect_do_thing . get (& * reflect_value ). unwrap ();
151151
152152// Which means we can now call do_thing(). Magic!
Original file line number Diff line number Diff line change @@ -49,10 +49,8 @@ pub trait RegisterTypeBuilder {
4949impl RegisterTypeBuilder for AppBuilder {
5050 fn register_type < T : GetTypeRegistration > ( & mut self ) -> & mut Self {
5151 {
52- let registry = & mut self . resources ( ) . get_mut :: < TypeRegistryArc > ( ) . unwrap ( ) ;
53- registry
54- . write ( )
55- . add_registration ( T :: get_type_registration ( ) ) ;
52+ let registry = self . resources ( ) . get_mut :: < TypeRegistryArc > ( ) . unwrap ( ) ;
53+ registry. write ( ) . register :: < T > ( ) ;
5654 }
5755 self
5856 }
Original file line number Diff line number Diff line change @@ -302,7 +302,7 @@ mod tests {
302302 let serialized = to_string_pretty ( & serializer, PrettyConfig :: default ( ) ) . unwrap ( ) ;
303303
304304 let mut deserializer = Deserializer :: from_str ( & serialized) . unwrap ( ) ;
305- let reflect_deserializer = ReflectDeserializer :: new ( & mut registry) ;
305+ let reflect_deserializer = ReflectDeserializer :: new ( & registry) ;
306306 let value = reflect_deserializer. deserialize ( & mut deserializer) . unwrap ( ) ;
307307 let dynamic_struct = value. take :: < DynamicStruct > ( ) . unwrap ( ) ;
308308
Original file line number Diff line number Diff line change @@ -32,10 +32,9 @@ pub trait GetTypeRegistration {
3232impl TypeRegistry {
3333 pub fn register < T > ( & mut self )
3434 where
35- T : Reflect ,
35+ T : GetTypeRegistration ,
3636 {
37- let registration = TypeRegistration :: of :: < T > ( ) ;
38- self . add_registration ( registration) ;
37+ self . add_registration ( T :: get_type_registration ( ) ) ;
3938 }
4039
4140 pub fn add_registration ( & mut self , registration : TypeRegistration ) {
Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ fn setup(type_registry: Res<TypeRegistry>) {
3131 value : "Hello" . to_string ( ) ,
3232 } ) ;
3333
34- // This means we no longer have direct access to MyType or it methods. We can only call Reflect methods on reflect_value.
35- // What if we want to call `do_thing` on our type? We could downcast using reflect_value.get ::<MyType>(), but what if we
34+ // This means we no longer have direct access to MyType or its methods. We can only call Reflect methods on reflect_value.
35+ // What if we want to call `do_thing` on our type? We could downcast using reflect_value.downcast_ref ::<MyType>(), but what if we
3636 // don't know the type at compile time?
3737
3838 // Normally in rust we would be out of luck at this point. Lets use our new reflection powers to do something cool!
@@ -44,7 +44,7 @@ fn setup(type_registry: Res<TypeRegistry>) {
4444 . get_type_data :: < ReflectDoThing > ( reflect_value. type_id ( ) )
4545 . unwrap ( ) ;
4646
47- // We can use this generated type to convert our `&dyn Reflect` reference to an `&dyn DoThing` reference
47+ // We can use this generated type to convert our `&dyn Reflect` reference to a `&dyn DoThing` reference
4848 let my_trait: & dyn DoThing = reflect_do_thing. get ( & * reflect_value) . unwrap ( ) ;
4949
5050 // Which means we can now call do_thing(). Magic!
You can’t perform that action at this time.
0 commit comments