use crate::{
alloc,
depot::{
self, capacity,
index::Initialized,
queue::{
indexed::planes::{bound, resident},
links,
},
},
};
impl<'storage, 'id, T, M, const N: usize, P: Ord, C: alloc::raw::Extent, const E: usize>
resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>
{
pub unsafe fn available(
&mut self,
) -> Option<resident::Available<'_, 'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>>
{
const { assert!(E < N) };
let index = self.source.core.queues[E].first()?;
let key = bound::ActiveKey(capacity::Key::new(unsafe { depot::raw::Proof::new(index) }));
Some(resident::Available { source: self, key })
}
}
impl<'id> resident::Key<'id> {
pub fn from_live<
'loan,
'storage,
T,
M,
const N: usize,
P: Ord,
C: alloc::raw::Extent,
const E: usize,
>(
source: depot::raw::Proof<
(
&'loan resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>,
links::Index,
),
Initialized<resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>>,
>,
) -> Self {
let (_, index) = source.into_inner();
Self(bound::ActiveKey(capacity::Key::new(unsafe {
depot::raw::Proof::new(index)
})))
}
}
unsafe impl<
'loan,
'storage,
'id,
T,
M,
const N: usize,
P: Ord,
C: alloc::raw::Extent,
const E: usize,
>
depot::raw::Project<
links::Index,
resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>,
> for &'loan resident::Scope<'storage, 'id, T, M, N, bound::Active<'storage, P, C>, E>
{
type Output = &'loan T;
unsafe fn project(self, index: links::Index) -> Self::Output {
let key = resident::Key::from_live(unsafe { depot::raw::Proof::new((self, index)) });
self.get(key)
}
}