use std::{mem, num::NonZero};
#[repr(C)]
pub struct StagedValue<Key, Queued, Parked> {
pub(in crate::depot) key: mem::ManuallyDrop<Key>,
pub(in crate::depot) value: Value<Queued, Parked>,
}
#[repr(C)]
pub(in crate::depot) union Value<Queued, Parked> {
queued: mem::ManuallyDrop<Queued>,
parked: mem::ManuallyDrop<Parked>,
}
impl<Key, Queued, Parked> StagedValue<Key, Queued, Parked> {
pub fn queued(key: Key, value: Queued) -> Self {
Self {
key: mem::ManuallyDrop::new(key),
value: Value {
queued: mem::ManuallyDrop::new(value),
},
}
}
pub fn parked(key: Key, value: Parked) -> Self {
Self {
key: mem::ManuallyDrop::new(key),
value: Value {
parked: mem::ManuallyDrop::new(value),
},
}
}
pub fn key(&self) -> &Key {
&self.key
}
pub unsafe fn parked_ref(&self) -> &Parked {
unsafe { &self.value.parked }
}
}
pub unsafe trait LinkedNode: Sized {
type Input: Copy;
fn new(input: Self::Input) -> Self;
fn reset(&mut self, input: Self::Input);
fn next(&self) -> Option<NonZero<u32>>;
unsafe fn set_next(&mut self, next: Option<NonZero<u32>>);
}