Skip to content

Commit 24b319f

Browse files
Add reflect for type id (#12495)
# 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 <[email protected]>
1 parent 16fb995 commit 24b319f

File tree

1 file changed

+8
-0
lines changed
  • crates/bevy_reflect/src/impls

1 file changed

+8
-0
lines changed

crates/bevy_reflect/src/impls/std.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl_reflect_value!(::std::path::PathBuf(
9696
Deserialize,
9797
Default
9898
));
99+
impl_reflect_value!(::std::any::TypeId(Debug, Hash, PartialEq,));
99100
impl_reflect_value!(
100101
::core::result::Result < T: Clone + Reflect + TypePath,
101102
E: Clone + Reflect + TypePath > ()
@@ -2104,6 +2105,13 @@ mod tests {
21042105
assert_eq!(path, output);
21052106
}
21062107

2108+
#[test]
2109+
fn type_id_should_from_reflect() {
2110+
let type_id = std::any::TypeId::of::<usize>();
2111+
let output = <std::any::TypeId as FromReflect>::from_reflect(&type_id).unwrap();
2112+
assert_eq!(type_id, output);
2113+
}
2114+
21072115
#[test]
21082116
fn static_str_should_from_reflect() {
21092117
let expected = "Hello, World!";

0 commit comments

Comments
 (0)