use crate::{ArchetypeStorage, Component, EntityId};
pub struct Entry<'a> {
pub(crate) arch: &'a ArchetypeStorage,
pub(crate) entity: EntityId,
}
impl<'a> Entry<'a> {
pub fn entity(&self) -> &EntityId {
&self.entity
}
pub fn get<C: Component>(&self) -> Option<&C> {
let comp = self.arch.component::<C>()?;
Some(unsafe { comp.get_unchecked(self.entity.id) })
}
}
pub struct EntryMut<'a> {
pub(crate) arch: &'a mut ArchetypeStorage,
pub(crate) entity: EntityId,
}
impl EntryMut<'_> {
pub fn entity(&self) -> &EntityId {
&self.entity
}
pub fn get<C: Component>(&self) -> Option<&C> {
let comp = self.arch.component::<C>()?;
Some(unsafe { comp.get_unchecked(self.entity.id) })
}
pub fn get_mut<C: Component>(&mut self) -> Option<&mut C> {
let mut comp = self.arch.component_mut::<C>()?;
Some(unsafe { comp.get_unchecked_mut(self.entity.id) })
}
}