use std::{iter, mem};
use crate::depot;
pub mod chain;
pub mod fifo;
pub mod head;
pub mod raw;
pub struct Iter<'a, T, Tag = ()> {
store: &'a raw::Store<T>,
current: raw::Index<Tag>,
}
impl<'a, T, Tag> Iter<'a, T, Tag> {
pub fn next_entry(&mut self) -> Option<(raw::Index<Tag>, &'a T)> {
let index = self.current;
self.next().map(|value| (index, value))
}
pub(crate) unsafe fn new(store: &'a raw::Store<T>, current: raw::Index<Tag>) -> Self {
Self { store, current }
}
pub(crate) unsafe fn next_live(&mut self) -> &'a T {
let slot = unsafe { self.store.slot(self.current.raw()) };
self.current = slot.next();
unsafe { &*slot.value_ptr() }
}
}
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 == raw::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) -> &raw::Store<T>;
}
pub(in crate::depot) use sealed::Sealed;
mod sealed;
#[derive(Debug)]
pub enum Same {}
#[derive(Debug)]
pub enum Available {}
impl depot::raw::Sealed for Same {}
impl depot::raw::Sealed for Available {}