Update Entity and Relation::try_from

main
copygirl 1 month ago
parent c7b7084c32
commit 4663d46bee
  1. 7
      src/ecs/entity.rs
  2. 7
      src/ecs/relation.rs

@ -116,7 +116,12 @@ impl TryFrom<Component> for Entity {
type Error = (); type Error = ();
#[inline] #[inline]
fn try_from(component: Component) -> Result<Self, Self::Error> { fn try_from(component: Component) -> Result<Self, Self::Error> {
Self::from_bits(component.to_bits()).ok_or(()) if component.is_entity() {
// SAFETY: If component is valid and an entity, bitwise conversion is valid.
Ok(unsafe { Self::from_bits_unchecked(component.to_bits()) })
} else {
Err(())
}
} }
} }

@ -98,7 +98,12 @@ impl TryFrom<Component> for Relation {
type Error = (); type Error = ();
#[inline] #[inline]
fn try_from(component: Component) -> Result<Self, Self::Error> { fn try_from(component: Component) -> Result<Self, Self::Error> {
Self::from_bits(component.to_bits()).ok_or(()) if component.is_relation() {
// SAFETY: If component is valid and a relation, bitwise conversion is valid.
Ok(unsafe { Self::from_bits_unchecked(component.to_bits()) })
} else {
Err(())
}
} }
} }

Loading…
Cancel
Save