diff --git a/crates/bevy_reflect/README.md b/crates/bevy_reflect/README.md index 2fdc854d24e70e..30eea5ea196066 100644 --- a/crates/bevy_reflect/README.md +++ b/crates/bevy_reflect/README.md @@ -132,8 +132,8 @@ let reflect_value: Box = Box::new(MyType { value: "Hello".to_string(), }); -// This means we no longer have direct access to MyType or it methods. We can only call Reflect methods on reflect_value. -// What if we want to call `do_thing` on our type? We could downcast using reflect_value.get::(), but what if we +// This means we no longer have direct access to MyType or its methods. We can only call Reflect methods on reflect_value. +// What if we want to call `do_thing` on our type? We could downcast using reflect_value.downcast_ref::(), but what if we // don't know the type at compile time? // 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 .get_type_data::(reflect_value.type_id()) .unwrap(); -// We can use this generated type to convert our `&dyn Reflect` reference to an `&dyn DoThing` reference +// We can use this generated type to convert our `&dyn Reflect` reference to a `&dyn DoThing` reference let my_trait: &dyn DoThing = reflect_do_thing.get(&*reflect_value).unwrap(); // Which means we can now call do_thing(). Magic! diff --git a/crates/bevy_reflect/src/impls/bevy_app.rs b/crates/bevy_reflect/src/impls/bevy_app.rs index 6698d6711a9d67..8c142783a0ecf8 100644 --- a/crates/bevy_reflect/src/impls/bevy_app.rs +++ b/crates/bevy_reflect/src/impls/bevy_app.rs @@ -49,10 +49,8 @@ pub trait RegisterTypeBuilder { impl RegisterTypeBuilder for AppBuilder { fn register_type(&mut self) -> &mut Self { { - let registry = &mut self.resources().get_mut::().unwrap(); - registry - .write() - .add_registration(T::get_type_registration()); + let registry = self.resources().get_mut::().unwrap(); + registry.write().register::(); } self } diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 2b207f6c7f4f72..f75ad00fd57121 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -302,7 +302,7 @@ mod tests { let serialized = to_string_pretty(&serializer, PrettyConfig::default()).unwrap(); let mut deserializer = Deserializer::from_str(&serialized).unwrap(); - let reflect_deserializer = ReflectDeserializer::new(&mut registry); + let reflect_deserializer = ReflectDeserializer::new(®istry); let value = reflect_deserializer.deserialize(&mut deserializer).unwrap(); let dynamic_struct = value.take::().unwrap(); diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index 70a8952daf5c61..6fa39145b3540e 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -32,10 +32,9 @@ pub trait GetTypeRegistration { impl TypeRegistry { pub fn register(&mut self) where - T: Reflect, + T: GetTypeRegistration, { - let registration = TypeRegistration::of::(); - self.add_registration(registration); + self.add_registration(T::get_type_registration()); } pub fn add_registration(&mut self, registration: TypeRegistration) { diff --git a/examples/reflection/trait_reflection.rs b/examples/reflection/trait_reflection.rs index 58d68f67c57a6c..f7d7a1c985f7af 100644 --- a/examples/reflection/trait_reflection.rs +++ b/examples/reflection/trait_reflection.rs @@ -31,8 +31,8 @@ fn setup(type_registry: Res) { value: "Hello".to_string(), }); - // This means we no longer have direct access to MyType or it methods. We can only call Reflect methods on reflect_value. - // What if we want to call `do_thing` on our type? We could downcast using reflect_value.get::(), but what if we + // This means we no longer have direct access to MyType or its methods. We can only call Reflect methods on reflect_value. + // What if we want to call `do_thing` on our type? We could downcast using reflect_value.downcast_ref::(), but what if we // don't know the type at compile time? // 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) { .get_type_data::(reflect_value.type_id()) .unwrap(); - // We can use this generated type to convert our `&dyn Reflect` reference to an `&dyn DoThing` reference + // We can use this generated type to convert our `&dyn Reflect` reference to a `&dyn DoThing` reference let my_trait: &dyn DoThing = reflect_do_thing.get(&*reflect_value).unwrap(); // Which means we can now call do_thing(). Magic!