use std::mem;
pub(in crate::depot::queue::indexed) use front::Front;
use crate::depot::queue::{
indexed::{fifo, keyed},
links,
};
mod front;
impl<T> fifo::Store<T> {
pub(in crate::depot::queue::indexed) fn front_entry(&self) -> Option<Front<'_, T>> {
if self.state().is_empty() {
return None;
}
Some(Self::front_from(unsafe {
crate::depot::raw::Proof::new(self)
}))
}
pub(in crate::depot::queue::indexed) fn front_from(
source: crate::depot::raw::Proof<&Self, keyed::NonEmpty>,
) -> Front<'_, T> {
let owner = source.into_inner();
let index = unsafe { owner.state().front_key() };
unsafe { Front::new(owner.at(index)) }
}
}
impl<T> Drop for fifo::Store<T> {
fn drop(&mut self) {
if !mem::needs_drop::<T>() {
return;
}
let mut next = self.state().first();
while let Some(index) = next {
let entry = unsafe { self.at(index) };
let node = entry.slot();
next = links::Index::decode(node.hook.next.get());
unsafe { (*node.value.get()).assume_init_drop() };
}
}
}