impl PartialEq<Component> for Entity / Relation

wip/graph
copygirl 2 months ago
parent 9b821f26eb
commit ac16cbe527
  1. 8
      src/ecs/component.rs
  2. 7
      src/ecs/entity.rs
  3. 7
      src/ecs/relation.rs

@ -148,7 +148,9 @@ mod tests {
let entity = Entity::new_checked(1337, 42).unwrap(); let entity = Entity::new_checked(1337, 42).unwrap();
let component: Component = entity.into(); let component: Component = entity.into();
assert!(component.is_entity()); 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] #[test]
@ -156,6 +158,8 @@ mod tests {
let relation = Relation::new_checked(20, 21).unwrap(); let relation = Relation::new_checked(20, 21).unwrap();
let component: Component = relation.into(); let component: Component = relation.into();
assert!(component.is_relation()); 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);
} }
} }

@ -140,6 +140,13 @@ impl PartialEq for Entity {
} }
} }
impl PartialEq<Component> for Entity {
#[inline]
fn eq(&self, other: &Component) -> bool {
self.to_bits() == other.to_bits()
}
}
impl Ord for Entity { impl Ord for Entity {
#[inline] #[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering { fn cmp(&self, other: &Self) -> std::cmp::Ordering {

@ -122,6 +122,13 @@ impl PartialEq for Relation {
} }
} }
impl PartialEq<Component> for Relation {
#[inline]
fn eq(&self, other: &Component) -> bool {
self.to_bits() == other.to_bits()
}
}
impl Ord for Relation { impl Ord for Relation {
#[inline] #[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering { fn cmp(&self, other: &Self) -> std::cmp::Ordering {

Loading…
Cancel
Save