use std::{marker, pin};
use cycle::Policy;
use crate::depot::arena::slab::{entries, key::cycle, storage};
pub struct Anchored<
'a,
T,
Tag = (),
const MAX: u32 = { u32::MAX },
const RECYCLE: bool = false,
const PARTITIONS: usize = 1,
S = storage::Heap,
> where
cycle::Mode<RECYCLE>: Policy,
S: storage::Storage,
{
pub(in crate::depot) entry:
entries::Busy<'a, T, MAX, entries::Exclusive<RECYCLE>, PARTITIONS, (), S>,
pub(in crate::depot) tag: marker::PhantomData<fn() -> Tag>,
}
impl<'a, T, Tag, const MAX: u32, const RECYCLE: bool, const PARTITIONS: usize, S>
Anchored<'a, T, Tag, MAX, RECYCLE, PARTITIONS, S>
where
cycle::Mode<RECYCLE>: Policy,
S: storage::Storage,
{
pub fn get(&self) -> &T {
self.entry.value()
}
pub fn value(&mut self) -> pin::Pin<&mut T> {
unsafe { pin::Pin::new_unchecked(self.entry.value_mut()) }
}
pub fn into_value(self) -> pin::Pin<&'a mut T> {
unsafe { pin::Pin::new_unchecked(self.entry.into_mut()) }
}
pub fn discard(self) {
self.entry.discard();
}
}