#[derive(Debug)]
pub(crate) struct Arena<E>(Vec<E>);
impl<E> Default for Arena<E> {
fn default() -> Self {
Arena(Vec::new())
}
}
impl<E> Arena<E> {
pub(super) fn alloc(&mut self, entity: E) -> u32 {
let index = self.0.len() as u32;
self.0.push(entity);
index
}
pub(super) fn get(&self, index: u32) -> &E {
&self.0[index as usize]
}
pub(super) fn get_opt(&self, index: u32) -> Option<&E> {
self.0.get(index as usize)
}
pub(super) fn get_mut(&mut self, index: u32) -> &mut E {
&mut self.0[index as usize]
}
pub(super) fn len(&self) -> u32 {
self.0.len() as u32
}
pub(super) fn iter(&self) -> impl Iterator<Item = &E> {
self.0.iter()
}
}