pub struct SlotList<T, const SIZE: usize> {
inner: [Option<T>; SIZE],
}
impl<T, const SIZE: usize> SlotList<T, SIZE> {
pub const fn new() -> Self {
Self { inner: [const { None }; SIZE] }
}
pub fn insert_in_free_slot(&mut self, val: T) -> Option<(usize, &mut T)> {
let free_slot_index = self.inner.iter().position(|v| v.is_none());
if let Some(i) = free_slot_index {
self.inner[i] = Some(val);
Some((i, self.inner[i].as_mut().unwrap()))
} else {
None
}
}
pub fn free_slot(&mut self, index: usize) {
if index < SIZE {
self.inner[index] = None;
}
}
}