From ac16cbe527ef0127a4818cb0ec4cfeca85b1e46e Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 26 Sep 2024 23:34:46 +0200 Subject: [PATCH] impl PartialEq for Entity / Relation --- src/ecs/component.rs | 8 ++++++-- src/ecs/entity.rs | 7 +++++++ src/ecs/relation.rs | 9 ++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ecs/component.rs b/src/ecs/component.rs index 6b05bea..c309a62 100644 --- a/src/ecs/component.rs +++ b/src/ecs/component.rs @@ -148,7 +148,9 @@ mod tests { let entity = Entity::new_checked(1337, 42).unwrap(); let component: Component = entity.into(); assert!(component.is_entity()); - assert_eq!(entity, component.try_into().unwrap()); + + let back_to_entity: Entity = component.try_into().unwrap(); + assert_eq!(entity, back_to_entity); } #[test] @@ -156,6 +158,8 @@ mod tests { let relation = Relation::new_checked(20, 21).unwrap(); let component: Component = relation.into(); assert!(component.is_relation()); - assert_eq!(relation, component.try_into().unwrap()); + + let back_to_relation: Relation = component.try_into().unwrap(); + assert_eq!(relation, back_to_relation); } } diff --git a/src/ecs/entity.rs b/src/ecs/entity.rs index 8a4ed32..13b4e8d 100644 --- a/src/ecs/entity.rs +++ b/src/ecs/entity.rs @@ -140,6 +140,13 @@ impl PartialEq for Entity { } } +impl PartialEq for Entity { + #[inline] + fn eq(&self, other: &Component) -> bool { + self.to_bits() == other.to_bits() + } +} + impl Ord for Entity { #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering { diff --git a/src/ecs/relation.rs b/src/ecs/relation.rs index 742afc6..2959347 100644 --- a/src/ecs/relation.rs +++ b/src/ecs/relation.rs @@ -81,7 +81,7 @@ impl Relation { let target = bits as u32; let high = (bits >> 32) as u32; if let (kind, Flags::RELATION) = Flags::unpack(high)? { - Self::new_checked(kind, target) + Self::new_checked(kind, target) } else { None } @@ -122,6 +122,13 @@ impl PartialEq for Relation { } } +impl PartialEq for Relation { + #[inline] + fn eq(&self, other: &Component) -> bool { + self.to_bits() == other.to_bits() + } +} + impl Ord for Relation { #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering {