use super::MelinoeCell;
use crate::token::{ReadPermit, WritePermit};
pub trait CellSliceExt<'brand, T> {
fn borrow_slice<'a, P>(&'a self, permit: P) -> &'a [T]
where
P: ReadPermit<'brand> + 'a;
#[expect(
clippy::mut_from_ref,
reason = "exclusivity is supplied by the WritePermit (a &mut borrow of the brand's unique token), not by the &self slice reference — the GhostCell interior-mutability pattern"
)]
fn borrow_slice_mut<'a, P>(&'a self, permit: P) -> &'a mut [T]
where
P: WritePermit<'brand> + 'a;
}
impl<'brand, T> CellSliceExt<'brand, T> for [MelinoeCell<'brand, T>] {
#[inline]
fn borrow_slice<'a, P>(&'a self, _permit: P) -> &'a [T]
where
P: ReadPermit<'brand> + 'a,
{
let cell = MelinoeCell::slice_as_unsafe_cell(self);
unsafe { &*cell.get().cast_const() }
}
#[inline]
fn borrow_slice_mut<'a, P>(&'a self, _permit: P) -> &'a mut [T]
where
P: WritePermit<'brand> + 'a,
{
let cell = MelinoeCell::slice_as_unsafe_cell(self);
unsafe { &mut *cell.get() }
}
}