Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
soqb committed Jun 23, 2023
1 parent 469c927 commit bd0b407
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
28 changes: 4 additions & 24 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl_reflect_value!(isize(
));
impl_reflect_value!(f32(Debug, PartialEq, Serialize, Deserialize, Default));
impl_reflect_value!(f64(Debug, PartialEq, Serialize, Deserialize, Default));
impl_type_path!(str);
impl_reflect_value!(::alloc::string::String(
Debug,
Hash,
Expand Down Expand Up @@ -1071,8 +1072,6 @@ impl<T: TypePath + ?Sized> TypePath for &'static T {
static CELL: GenericTypePathCell = GenericTypePathCell::new();
CELL.get_or_insert::<Self, _>(|| format!("&{}", T::short_type_path()))
}

const TYPE_PATH_ID: TypePathId = TypePathId::from_base("&").with_generics(&[T::TYPE_PATH_ID]);
}

impl Reflect for Cow<'static, str> {
Expand Down Expand Up @@ -1179,8 +1178,6 @@ impl FromReflect for Cow<'static, str> {
}
}

impl<T: PathOnly> PathOnly for [T] where [T]: ToOwned {}

impl<T: TypePath> TypePath for [T]
where
[T]: ToOwned,
Expand All @@ -1196,8 +1193,6 @@ where
}
}

impl<T: ToOwned> PathOnly for T {}

impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
fn get(&self, index: usize) -> Option<&dyn Reflect> {
self.as_ref().get(index).map(|x| x as &dyn Reflect)
Expand Down Expand Up @@ -1229,7 +1224,7 @@ impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
T::from_reflect(&*value).unwrap_or_else(|| {
panic!(
"Attempted to insert invalid value of type {}.",
value.type_name()
value.reflect_type_path()
)
})
});
Expand All @@ -1244,7 +1239,7 @@ impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
let value = T::take_from_reflect(value).unwrap_or_else(|value| {
panic!(
"Attempted to push invalid value of type {}.",
value.type_name()
value.reflect_type_path()
)
});
self.to_mut().push(value);
Expand All @@ -1258,10 +1253,6 @@ impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
}

impl<T: FromReflect + Clone + TypePath> Reflect for Cow<'static, [T]> {
fn type_name(&self) -> &str {
std::any::type_name::<Self>()
}

fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
Expand Down Expand Up @@ -1434,18 +1425,6 @@ impl Typed for &'static Path {
}
}

impl TypePath for &'static Path {
fn type_path() -> &'static str {
static CELL: GenericTypePathCell = GenericTypePathCell::new();
CELL.get_or_insert::<Self, _>(|| "&std::path::Path".to_owned())
}

fn short_type_path() -> &'static str {
static CELL: GenericTypePathCell = GenericTypePathCell::new();
CELL.get_or_insert::<Self, _>(|| "&Path".to_owned())
}
}

impl GetTypeRegistration for &'static Path {
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration::of::<Self>();
Expand Down Expand Up @@ -1547,6 +1526,7 @@ impl Typed for Cow<'static, Path> {
}
}

impl_type_path!(::std::path::Path);
impl_type_path!(::alloc::borrow::Cow<'a: 'static, T: ToOwned + ?Sized>);

impl FromReflect for Cow<'static, Path> {
Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ mod tests {
let info = MyCowStr::type_info();
if let TypeInfo::Value(info) = info {
assert!(info.is::<MyCowStr>());
assert_eq!(std::any::type_name::<MyCowStr>(), info.type_name());
assert_eq!(std::any::type_name::<MyCowStr>(), info.type_path());
} else {
panic!("Expected `TypeInfo::Value`");
}
Expand All @@ -1405,8 +1405,11 @@ mod tests {
if let TypeInfo::List(info) = info {
assert!(info.is::<MyCowSlice>());
assert!(info.item_is::<u8>());
assert_eq!(std::any::type_name::<MyCowSlice>(), info.type_name());
assert_eq!(std::any::type_name::<u8>(), info.item_type_name());
assert_eq!(std::any::type_name::<MyCowSlice>(), info.type_path());
assert_eq!(
std::any::type_name::<u8>(),
info.item_type_path_vtable().path()
);
} else {
panic!("Expected `TypeInfo::List`");
}
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_reflect/src/type_path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

/// A static accessor to type paths and names.
///
/// The engine uses this trait over [`std::any::type_name`] for stability and flexibility.
Expand Down

0 comments on commit bd0b407

Please sign in to comment.