Skip to content

Commit

Permalink
impl GetTypeRegistration for HashMap<K, V> and Cow<'static, str>
Browse files Browse the repository at this point in the history
  • Loading branch information
CleanCut committed Mar 8, 2021
1 parent 844782c commit 364ba51
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl<T: Reflect + for<'de> Deserialize<'de>> GetTypeRegistration for Vec<T> {
registration
}
}

impl<K: Reflect + Clone + Eq + Hash, V: Reflect + Clone> Map for HashMap<K, V> {
fn get(&self, key: &dyn Reflect) -> Option<&dyn Reflect> {
key.downcast_ref::<K>()
Expand Down Expand Up @@ -214,6 +215,18 @@ impl<K: Reflect + Clone + Eq + Hash, V: Reflect + Clone> Reflect for HashMap<K,
}
}

impl<K, V> GetTypeRegistration for HashMap<K, V>
where
K: Reflect + Clone + Eq + Hash + for<'de> Deserialize<'de>,
V: Reflect + Clone + for<'de> Deserialize<'de>,
{
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration::of::<HashMap<K, V>>();
registration.insert::<ReflectDeserialize>(FromType::<HashMap<K, V>>::from_type());
registration
}
}

impl Reflect for Cow<'static, str> {
fn type_name(&self) -> &str {
std::any::type_name::<Self>()
Expand Down Expand Up @@ -273,3 +286,11 @@ impl Reflect for Cow<'static, str> {
Some(Serializable::Borrowed(self))
}
}

impl GetTypeRegistration for Cow<'static, str> {
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration::of::<Cow<'static, str>>();
registration.insert::<ReflectDeserialize>(FromType::<Cow<'static, str>>::from_type());
registration
}
}

0 comments on commit 364ba51

Please sign in to comment.