Skip to content

Commit 6ada356

Browse files
committed
bevy_reflect: Fix misplaced impls (#6829)
# Objective > Followup to [this](#6755 (comment)) comment Rearrange the impls in the `impls/std.rs` file. The issue was that I had accidentally misplaced the impl for `Option<T>` and put it between the `Cow<'static, str>` impls. This is just a slight annoyance and readability issue. ## Solution Move the `Option<T>` and `&'static Path` impls around to be more readable.
1 parent 9191880 commit 6ada356

File tree

1 file changed

+160
-160
lines changed
  • crates/bevy_reflect/src/impls

1 file changed

+160
-160
lines changed

crates/bevy_reflect/src/impls/std.rs

Lines changed: 160 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -668,166 +668,6 @@ impl_array_get_type_registration! {
668668
30 31 32
669669
}
670670

671-
impl Reflect for Cow<'static, str> {
672-
fn type_name(&self) -> &str {
673-
std::any::type_name::<Self>()
674-
}
675-
676-
fn get_type_info(&self) -> &'static TypeInfo {
677-
<Self as Typed>::type_info()
678-
}
679-
680-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
681-
self
682-
}
683-
684-
fn as_any(&self) -> &dyn Any {
685-
self
686-
}
687-
688-
fn as_any_mut(&mut self) -> &mut dyn Any {
689-
self
690-
}
691-
692-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
693-
self
694-
}
695-
696-
fn as_reflect(&self) -> &dyn Reflect {
697-
self
698-
}
699-
700-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
701-
self
702-
}
703-
704-
fn apply(&mut self, value: &dyn Reflect) {
705-
let value = value.as_any();
706-
if let Some(value) = value.downcast_ref::<Self>() {
707-
*self = value.clone();
708-
} else {
709-
panic!("Value is not a {}.", std::any::type_name::<Self>());
710-
}
711-
}
712-
713-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
714-
*self = value.take()?;
715-
Ok(())
716-
}
717-
718-
fn reflect_ref(&self) -> ReflectRef {
719-
ReflectRef::Value(self)
720-
}
721-
722-
fn reflect_mut(&mut self) -> ReflectMut {
723-
ReflectMut::Value(self)
724-
}
725-
726-
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
727-
ReflectOwned::Value(self)
728-
}
729-
730-
fn clone_value(&self) -> Box<dyn Reflect> {
731-
Box::new(self.clone())
732-
}
733-
734-
fn reflect_hash(&self) -> Option<u64> {
735-
let mut hasher = crate::ReflectHasher::default();
736-
Hash::hash(&std::any::Any::type_id(self), &mut hasher);
737-
Hash::hash(self, &mut hasher);
738-
Some(hasher.finish())
739-
}
740-
741-
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
742-
let value = value.as_any();
743-
if let Some(value) = value.downcast_ref::<Self>() {
744-
Some(std::cmp::PartialEq::eq(self, value))
745-
} else {
746-
Some(false)
747-
}
748-
}
749-
}
750-
751-
impl Reflect for &'static Path {
752-
fn type_name(&self) -> &str {
753-
std::any::type_name::<Self>()
754-
}
755-
756-
fn get_type_info(&self) -> &'static TypeInfo {
757-
<Self as Typed>::type_info()
758-
}
759-
760-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
761-
self
762-
}
763-
764-
fn as_any(&self) -> &dyn Any {
765-
self
766-
}
767-
768-
fn as_any_mut(&mut self) -> &mut dyn Any {
769-
self
770-
}
771-
772-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
773-
self
774-
}
775-
776-
fn as_reflect(&self) -> &dyn Reflect {
777-
self
778-
}
779-
780-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
781-
self
782-
}
783-
784-
fn apply(&mut self, value: &dyn Reflect) {
785-
let value = value.as_any();
786-
if let Some(&value) = value.downcast_ref::<Self>() {
787-
*self = value;
788-
} else {
789-
panic!("Value is not a {}.", std::any::type_name::<Self>());
790-
}
791-
}
792-
793-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
794-
*self = value.take()?;
795-
Ok(())
796-
}
797-
798-
fn reflect_ref(&self) -> ReflectRef {
799-
ReflectRef::Value(self)
800-
}
801-
802-
fn reflect_mut(&mut self) -> ReflectMut {
803-
ReflectMut::Value(self)
804-
}
805-
806-
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
807-
ReflectOwned::Value(self)
808-
}
809-
810-
fn clone_value(&self) -> Box<dyn Reflect> {
811-
Box::new(*self)
812-
}
813-
814-
fn reflect_hash(&self) -> Option<u64> {
815-
let mut hasher = crate::ReflectHasher::default();
816-
Hash::hash(&std::any::Any::type_id(self), &mut hasher);
817-
Hash::hash(self, &mut hasher);
818-
Some(hasher.finish())
819-
}
820-
821-
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
822-
let value = value.as_any();
823-
if let Some(value) = value.downcast_ref::<Self>() {
824-
Some(std::cmp::PartialEq::eq(self, value))
825-
} else {
826-
Some(false)
827-
}
828-
}
829-
}
830-
831671
impl<T: FromReflect> GetTypeRegistration for Option<T> {
832672
fn get_type_registration() -> TypeRegistration {
833673
TypeRegistration::of::<Option<T>>()
@@ -1074,6 +914,86 @@ impl<T: FromReflect> Typed for Option<T> {
1074914
}
1075915
}
1076916

917+
impl Reflect for Cow<'static, str> {
918+
fn type_name(&self) -> &str {
919+
std::any::type_name::<Self>()
920+
}
921+
922+
fn get_type_info(&self) -> &'static TypeInfo {
923+
<Self as Typed>::type_info()
924+
}
925+
926+
fn into_any(self: Box<Self>) -> Box<dyn Any> {
927+
self
928+
}
929+
930+
fn as_any(&self) -> &dyn Any {
931+
self
932+
}
933+
934+
fn as_any_mut(&mut self) -> &mut dyn Any {
935+
self
936+
}
937+
938+
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
939+
self
940+
}
941+
942+
fn as_reflect(&self) -> &dyn Reflect {
943+
self
944+
}
945+
946+
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
947+
self
948+
}
949+
950+
fn apply(&mut self, value: &dyn Reflect) {
951+
let value = value.as_any();
952+
if let Some(value) = value.downcast_ref::<Self>() {
953+
*self = value.clone();
954+
} else {
955+
panic!("Value is not a {}.", std::any::type_name::<Self>());
956+
}
957+
}
958+
959+
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
960+
*self = value.take()?;
961+
Ok(())
962+
}
963+
964+
fn reflect_ref(&self) -> ReflectRef {
965+
ReflectRef::Value(self)
966+
}
967+
968+
fn reflect_mut(&mut self) -> ReflectMut {
969+
ReflectMut::Value(self)
970+
}
971+
972+
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
973+
ReflectOwned::Value(self)
974+
}
975+
976+
fn clone_value(&self) -> Box<dyn Reflect> {
977+
Box::new(self.clone())
978+
}
979+
980+
fn reflect_hash(&self) -> Option<u64> {
981+
let mut hasher = crate::ReflectHasher::default();
982+
Hash::hash(&std::any::Any::type_id(self), &mut hasher);
983+
Hash::hash(self, &mut hasher);
984+
Some(hasher.finish())
985+
}
986+
987+
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
988+
let value = value.as_any();
989+
if let Some(value) = value.downcast_ref::<Self>() {
990+
Some(std::cmp::PartialEq::eq(self, value))
991+
} else {
992+
Some(false)
993+
}
994+
}
995+
}
996+
1077997
impl Typed for Cow<'static, str> {
1078998
fn type_info() -> &'static TypeInfo {
1079999
static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();
@@ -1102,6 +1022,86 @@ impl FromReflect for Cow<'static, str> {
11021022
}
11031023
}
11041024

1025+
impl Reflect for &'static Path {
1026+
fn type_name(&self) -> &str {
1027+
std::any::type_name::<Self>()
1028+
}
1029+
1030+
fn get_type_info(&self) -> &'static TypeInfo {
1031+
<Self as Typed>::type_info()
1032+
}
1033+
1034+
fn into_any(self: Box<Self>) -> Box<dyn Any> {
1035+
self
1036+
}
1037+
1038+
fn as_any(&self) -> &dyn Any {
1039+
self
1040+
}
1041+
1042+
fn as_any_mut(&mut self) -> &mut dyn Any {
1043+
self
1044+
}
1045+
1046+
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
1047+
self
1048+
}
1049+
1050+
fn as_reflect(&self) -> &dyn Reflect {
1051+
self
1052+
}
1053+
1054+
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
1055+
self
1056+
}
1057+
1058+
fn apply(&mut self, value: &dyn Reflect) {
1059+
let value = value.as_any();
1060+
if let Some(&value) = value.downcast_ref::<Self>() {
1061+
*self = value;
1062+
} else {
1063+
panic!("Value is not a {}.", std::any::type_name::<Self>());
1064+
}
1065+
}
1066+
1067+
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
1068+
*self = value.take()?;
1069+
Ok(())
1070+
}
1071+
1072+
fn reflect_ref(&self) -> ReflectRef {
1073+
ReflectRef::Value(self)
1074+
}
1075+
1076+
fn reflect_mut(&mut self) -> ReflectMut {
1077+
ReflectMut::Value(self)
1078+
}
1079+
1080+
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
1081+
ReflectOwned::Value(self)
1082+
}
1083+
1084+
fn clone_value(&self) -> Box<dyn Reflect> {
1085+
Box::new(*self)
1086+
}
1087+
1088+
fn reflect_hash(&self) -> Option<u64> {
1089+
let mut hasher = crate::ReflectHasher::default();
1090+
Hash::hash(&std::any::Any::type_id(self), &mut hasher);
1091+
Hash::hash(self, &mut hasher);
1092+
Some(hasher.finish())
1093+
}
1094+
1095+
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
1096+
let value = value.as_any();
1097+
if let Some(value) = value.downcast_ref::<Self>() {
1098+
Some(std::cmp::PartialEq::eq(self, value))
1099+
} else {
1100+
Some(false)
1101+
}
1102+
}
1103+
}
1104+
11051105
impl Typed for &'static Path {
11061106
fn type_info() -> &'static TypeInfo {
11071107
static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();

0 commit comments

Comments
 (0)