use std::convert;
use crate::depot::arena::slab::{self, key::cycle};
use cycle::Policy;
mod sealed;
pub(in crate::depot) use sealed::Sealed;
pub trait Mode: Sealed {
type Busy: Copy + Eq;
type Cycle: Policy;
const TAKEN: slab::State<Self::Busy, <Self::Cycle as Policy>::Retired>;
const REENTRANT: bool;
}
pub struct Exclusive<const RECYCLE: bool = false>;
impl<const RECYCLE: bool> Mode for Exclusive<RECYCLE>
where
cycle::Mode<RECYCLE>: Policy,
{
type Busy = convert::Infallible;
type Cycle = cycle::Mode<RECYCLE>;
const TAKEN: slab::State<Self::Busy, <Self::Cycle as Policy>::Retired> = slab::State::Occupied;
const REENTRANT: bool = false;
}
impl<const RECYCLE: bool> Sealed for Exclusive<RECYCLE> {}
pub struct Interior<const RECYCLE: bool = false>;
impl<const RECYCLE: bool> Mode for Interior<RECYCLE>
where
cycle::Mode<RECYCLE>: Policy,
{
type Busy = ();
type Cycle = cycle::Mode<RECYCLE>;
const TAKEN: slab::State<Self::Busy, <Self::Cycle as Policy>::Retired> = slab::State::Busy(());
const REENTRANT: bool = true;
}
impl<const RECYCLE: bool> Sealed for Interior<RECYCLE> {}
pub struct Allocated;