1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::{ArchetypeStorage, Component, EntityId};
pub struct Entry<'a> {
pub(crate) arch: &'a ArchetypeStorage,
pub(crate) entity: EntityId,
}
impl<'a> Entry<'a> {
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 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) })
}
}