Skip to content

Commit

Permalink
Add reflect for type id (#12495)
Browse files Browse the repository at this point in the history
# Objective

Add reflect for `std::any::TypeId`.

I couldn't add ReflectSerialize/ReflectDeserialize for it, it was giving
me an error. I don't really understand why, since it works for
`std::path::PathBuf`.

Co-authored-by: Charles Bournhonesque <cbournhonesque@snapchat.com>
  • Loading branch information
cBournhonesque and cbournhonesque-sc authored Mar 15, 2024
1 parent 16fb995 commit 24b319f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl_reflect_value!(::std::path::PathBuf(
Deserialize,
Default
));
impl_reflect_value!(::std::any::TypeId(Debug, Hash, PartialEq,));
impl_reflect_value!(
::core::result::Result < T: Clone + Reflect + TypePath,
E: Clone + Reflect + TypePath > ()
Expand Down Expand Up @@ -2104,6 +2105,13 @@ mod tests {
assert_eq!(path, output);
}

#[test]
fn type_id_should_from_reflect() {
let type_id = std::any::TypeId::of::<usize>();
let output = <std::any::TypeId as FromReflect>::from_reflect(&type_id).unwrap();
assert_eq!(type_id, output);
}

#[test]
fn static_str_should_from_reflect() {
let expected = "Hello, World!";
Expand Down

0 comments on commit 24b319f

Please sign in to comment.