use crate::depot::queue::links;
pub(in crate::depot) unsafe trait Membership<const LINKED: bool>:
Sized
{
type Output;
fn parts(
&self,
) -> (
&links::Chain<u32>,
impl crate::depot::raw::Hooks + '_,
links::Index,
);
unsafe fn finish(self) -> Self::Output;
fn transition(self) -> Self::Output {
{
let (queue, hooks, index) = self.parts();
unsafe {
if LINKED {
queue.unlink(&hooks, index).idle();
} else {
queue.link_back(&hooks, index);
}
}
}
unsafe { self.finish() }
}
}
pub(in crate::depot) unsafe trait Removal<'a, C: crate::depot::raw::ChainCount>:
Sized
{
fn links(&self) -> &'a links::Chain<C>;
unsafe fn apply(self) -> links::Detached<'a>;
fn commit(self) -> links::Detached<'a>
where
C: 'a,
{
let count = C::storage((unsafe { self.links().parts() }).2);
let next = count.map(|count| count.get() - 1);
let vacant = unsafe { self.apply() };
if let Some((count, next)) = count.zip(next) {
count.set(next);
}
vacant
}
}