Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bevy_reflect: Add
GetTypeRegistration
impl for reflected tuples (#4226
) # Objective Reflected tuples do not implement `GetTypeRegistration`, preventing us from registering our tuples, like: ```rust app.register_type::<(i32, i32)>(); ``` This is especially important for things like using #4042 to improve the scene format or implementing #4154 to recursively register fields. ## Solution Added an implementation to the tuple macro: ```rust impl<$($name: Reflect + for<'de> Deserialize<'de>),*> GetTypeRegistration for ($($name,)*) { fn get_type_registration() -> TypeRegistration { let mut registration = TypeRegistration::of::<($($name,)*)>(); registration.insert::<ReflectDeserialize>(FromType::<($($name,)*)>::from_type()); registration } } ``` This requires that the tuple's types implement `Deserialize`. This is exactly how `Vec` and `HashMap` handle it: ```rust impl<T: FromReflect + for<'de> Deserialize<'de>> GetTypeRegistration for Vec<T> { fn get_type_registration() -> TypeRegistration { let mut registration = TypeRegistration::of::<Vec<T>>(); registration.insert::<ReflectDeserialize>(FromType::<Vec<T>>::from_type()); registration } } ```
- Loading branch information