From 3855bf132a7e5359ed75c27f8afc3db724280d44 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Fri, 15 Mar 2024 20:56:31 -0400 Subject: [PATCH 1/3] add reflect for BinaryHeap --- crates/bevy_reflect/src/impls/std.rs | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index c35ec3d40ca34..d3650862b0a2c 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -402,6 +402,109 @@ impl_reflect_for_veclike!( VecDeque:: ); + +impl Reflect for ::alloc::collections::BinaryHeap { + fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { + Some(::type_info()) + } + + fn into_any(self: Box) -> Box { + self + } + + fn as_any(&self) -> &dyn Any { + self + } + + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + + fn into_reflect(self: Box) -> Box { + self + } + + fn as_reflect(&self) -> &dyn Reflect { + self + } + + fn as_reflect_mut(&mut self) -> &mut dyn Reflect { + self + } + + fn apply(&mut self, value: &dyn Reflect) { + crate::list_apply(self, value); + } + + fn set(&mut self, value: Box) -> Result<(), Box> { + *self = value.take()?; + Ok(()) + } + + fn reflect_kind(&self) -> ReflectKind { + ReflectKind::List + } + + fn reflect_ref(&self) -> ReflectRef { + ReflectRef::List(self) + } + + fn reflect_mut(&mut self) -> ReflectMut { + ReflectMut::List(self) + } + + fn reflect_owned(self: Box) -> ReflectOwned { + ReflectOwned::List(self) + } + + fn clone_value(&self) -> Box { + Box::new(self.clone_dynamic()) + } + + fn reflect_hash(&self) -> Option { + crate::list_hash(self) + } + + fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { + crate::list_partial_eq(self, value) + } +} + +impl Typed for ::alloc::collections::BinaryHeap { + fn type_info() -> &'static TypeInfo { + static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); + CELL.get_or_insert::(|| TypeInfo::List(ListInfo::new::())) + } +} + +impl GetTypeRegistration for ::alloc::collections::BinaryHeap { +fn get_type_registration() -> TypeRegistration { + let mut registration = TypeRegistration::of::<::alloc::collections::BinaryHeap>(); + registration.insert::(FromType::<::alloc::collections::BinaryHeap>::from_type()); + registration +} + +fn register_type_dependencies(registry: &mut TypeRegistry) { + registry.register::(); +} +} + +impl FromReflect for ::alloc::collections::BinaryHeap { +fn from_reflect(reflect: &dyn Reflect) -> Option { + if let ReflectRef::List(ref_list) = reflect.reflect_ref() { + let mut new_list = Self::with_capacity(ref_list.len()); + for field in ref_list.iter() { + ::alloc::collections::BinaryHeap::::push(&mut new_list, T::from_reflect(field)?); + } + Some(new_list) + } else { + None + } +} +} + +impl_type_path!(::alloc::collections::BinaryHeap); + macro_rules! impl_reflect_for_hashmap { ($ty:path) => { impl Map for $ty From 40ae96ffba42d05bda49d128215f6755a7521787 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Sun, 17 Mar 2024 17:46:29 -0400 Subject: [PATCH 2/3] represent as reflect value --- crates/bevy_reflect/src/impls/std.rs | 103 +-------------------------- 1 file changed, 1 insertion(+), 102 deletions(-) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index d3650862b0a2c..4f633680a6ed5 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -219,6 +219,7 @@ impl_reflect_value!(::std::ffi::OsString( )); #[cfg(not(any(unix, windows)))] impl_reflect_value!(::std::ffi::OsString(Debug, Hash, PartialEq)); +impl_reflect_value!(::alloc::collections::BinaryHeap); macro_rules! impl_reflect_for_veclike { ($ty:path, $insert:expr, $remove:expr, $push:expr, $pop:expr, $sub:ty) => { @@ -403,108 +404,6 @@ impl_reflect_for_veclike!( ); -impl Reflect for ::alloc::collections::BinaryHeap { - fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { - Some(::type_info()) - } - - fn into_any(self: Box) -> Box { - self - } - - fn as_any(&self) -> &dyn Any { - self - } - - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } - - fn into_reflect(self: Box) -> Box { - self - } - - fn as_reflect(&self) -> &dyn Reflect { - self - } - - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { - self - } - - fn apply(&mut self, value: &dyn Reflect) { - crate::list_apply(self, value); - } - - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) - } - - fn reflect_kind(&self) -> ReflectKind { - ReflectKind::List - } - - fn reflect_ref(&self) -> ReflectRef { - ReflectRef::List(self) - } - - fn reflect_mut(&mut self) -> ReflectMut { - ReflectMut::List(self) - } - - fn reflect_owned(self: Box) -> ReflectOwned { - ReflectOwned::List(self) - } - - fn clone_value(&self) -> Box { - Box::new(self.clone_dynamic()) - } - - fn reflect_hash(&self) -> Option { - crate::list_hash(self) - } - - fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { - crate::list_partial_eq(self, value) - } -} - -impl Typed for ::alloc::collections::BinaryHeap { - fn type_info() -> &'static TypeInfo { - static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); - CELL.get_or_insert::(|| TypeInfo::List(ListInfo::new::())) - } -} - -impl GetTypeRegistration for ::alloc::collections::BinaryHeap { -fn get_type_registration() -> TypeRegistration { - let mut registration = TypeRegistration::of::<::alloc::collections::BinaryHeap>(); - registration.insert::(FromType::<::alloc::collections::BinaryHeap>::from_type()); - registration -} - -fn register_type_dependencies(registry: &mut TypeRegistry) { - registry.register::(); -} -} - -impl FromReflect for ::alloc::collections::BinaryHeap { -fn from_reflect(reflect: &dyn Reflect) -> Option { - if let ReflectRef::List(ref_list) = reflect.reflect_ref() { - let mut new_list = Self::with_capacity(ref_list.len()); - for field in ref_list.iter() { - ::alloc::collections::BinaryHeap::::push(&mut new_list, T::from_reflect(field)?); - } - Some(new_list) - } else { - None - } -} -} - -impl_type_path!(::alloc::collections::BinaryHeap); - macro_rules! impl_reflect_for_hashmap { ($ty:path) => { impl Map for $ty From 38d5a2b4d8280ee214c211cbdf9bdd9203546bfa Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Sun, 17 Mar 2024 17:49:52 -0400 Subject: [PATCH 3/3] fmt --- crates/bevy_reflect/src/impls/std.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 4f633680a6ed5..3b50abb0d9fdf 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -403,7 +403,6 @@ impl_reflect_for_veclike!( VecDeque:: ); - macro_rules! impl_reflect_for_hashmap { ($ty:path) => { impl Map for $ty