use crate::depot::queue::links;
pub struct Detached<'a> {
hook: &'a links::Hook,
index: links::Index,
}
impl Detached<'_> {
pub const fn index(&self) -> links::Index {
self.index
}
pub(in crate::depot) unsafe fn push<H: crate::depot::raw::Hooks + ?Sized>(
self,
chain: &links::Chain,
hooks: &H,
) {
let change = unsafe { crate::depot::raw::Insert::<()>::from_vacant(chain, hooks, self) };
change.commit();
}
pub fn idle(self) {
self.hook.previous.set(self.index.raw());
self.hook.next.set(links::Index::END);
}
pub fn park(self) {
self.hook.previous.set(self.index.raw());
self.hook.next.set(self.index.raw());
}
}
impl<'a> Detached<'a> {
pub fn from_source(
proof: crate::depot::raw::Proof<(&'a links::Hook, links::Index), links::Vacant>,
) -> Self {
let (hook, index) = proof.into_inner();
Self { hook, index }
}
pub(in crate::depot) unsafe fn new(hook: &'a links::Hook, index: links::Index) -> Self {
Self { hook, index }
}
pub(in crate::depot) fn into_parts(self) -> (&'a links::Hook, links::Index) {
(self.hook, self.index)
}
}