Include ReflectFromReflect in all dynamic data types. (#17453)
# Objective Fixes #17416 ## Solution I just included ReflectFromReflect in all macros and implementations. I think this should be ok, at least it compiles properly and does fix the errors in my test code. ## Testing I generated a DynamicMap and tried to convert it into a concrete `HashMap` as a `Box<dyn Reflect>`. Without my fix, it doesn't work, because this line panics: ```rust let rfr = ty.data::<ReflectFromReflect>().unwrap(); ``` where `ty` is the `TypeRegistration` for the (matching) `HashMap`. I don't know why `ReflectFromReflect` wasn't included everywhere, I assume that it was an oversight and not an architecture decision I'm not aware of. # Migration Guide The hasher in reflected `HashMap`s and `HashSet`s now have to implement `Default`. This is the case for the ones provided by Bevy already, and is generally a sensible thing to do.
This commit is contained in:
parent
de5486725d
commit
000c362de0
@ -566,6 +566,7 @@ macro_rules! impl_reflect_for_veclike {
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<$ty>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<$ty>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<$ty>::from_type());
|
||||
registration
|
||||
}
|
||||
|
||||
@ -810,11 +811,12 @@ macro_rules! impl_reflect_for_hashmap {
|
||||
where
|
||||
K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash,
|
||||
V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,
|
||||
S: TypePath + BuildHasher + Send + Sync,
|
||||
S: TypePath + BuildHasher + Send + Sync + Default,
|
||||
{
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<Self>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
|
||||
registration
|
||||
}
|
||||
|
||||
@ -1035,11 +1037,12 @@ macro_rules! impl_reflect_for_hashset {
|
||||
impl<V, S> GetTypeRegistration for $ty
|
||||
where
|
||||
V: FromReflect + TypePath + GetTypeRegistration + Eq + Hash,
|
||||
S: TypePath + BuildHasher + Send + Sync,
|
||||
S: TypePath + BuildHasher + Send + Sync + Default,
|
||||
{
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<Self>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
|
||||
registration
|
||||
}
|
||||
|
||||
@ -1301,6 +1304,7 @@ where
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<Self>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
|
||||
registration
|
||||
}
|
||||
}
|
||||
@ -1665,6 +1669,7 @@ impl GetTypeRegistration for Cow<'static, str> {
|
||||
let mut registration = TypeRegistration::of::<Cow<'static, str>>();
|
||||
registration.insert::<ReflectDeserialize>(FromType::<Cow<'static, str>>::from_type());
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Cow<'static, str>>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Cow<'static, str>>::from_type());
|
||||
registration.insert::<ReflectSerialize>(FromType::<Cow<'static, str>>::from_type());
|
||||
registration
|
||||
}
|
||||
@ -2126,6 +2131,7 @@ impl GetTypeRegistration for &'static Path {
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<Self>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
|
||||
registration
|
||||
}
|
||||
}
|
||||
@ -2419,6 +2425,7 @@ impl GetTypeRegistration for &'static Location<'static> {
|
||||
fn get_type_registration() -> TypeRegistration {
|
||||
let mut registration = TypeRegistration::of::<Self>();
|
||||
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
|
||||
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
|
||||
registration
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user