use std::{iter, mem};
use crate::depot;
pub mod chain;
pub mod fifo;
pub mod head;
pub mod slots;
pub struct Iter<'a, T, Tag = ()> {
store: &'a slots::Store<T>,
current: slots::Index<Tag>,
}
impl<'a, T, Tag> Iter<'a, T, Tag> {
pub fn next_with_index(&mut self) -> Option<(slots::Index<Tag>, &'a T)> {
let index = self.current;
self.next().map(|value| (index, value))
}
pub(crate) unsafe fn new(store: &'a slots::Store<T>, current: slots::Index<Tag>) -> Self {
Self { store, current }
}
pub(crate) unsafe fn next_live(&mut self) -> &'a T {
let item = unsafe { self.store.value(self.current) };
self.current = unsafe { self.store.next(self.current) };
item
}
}
impl<'a, T: 'a, Tag> Iterator for Iter<'a, T, Tag> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
if self.current == slots::Index::NONE {
return None;
}
Some(unsafe { self.next_live() })
}
}
impl<T, Tag> iter::FusedIterator for Iter<'_, T, Tag> {}
impl<T, Tag> Clone for Iter<'_, T, Tag> {
fn clone(&self) -> Self {
*self
}
}
impl<T, Tag> Copy for Iter<'_, T, Tag> {}
const _: () = assert!(mem::size_of::<Iter<'static, u64, ()>>() == 2 * mem::size_of::<usize>());
pub trait Source<T>: Sealed<T> {
const TRACK: bool = true;
fn store(&self) -> &slots::Store<T>;
}
pub(in crate::depot) use sealed::Sealed;
mod sealed {
pub trait Sealed<T> {}
}
#[derive(Debug)]
pub enum Same {}
#[derive(Debug)]
pub enum Available {}
impl depot::raw::Sealed for Same {}
impl depot::raw::Sealed for Available {}