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;
#[allow(clippy::mut_from_ref)]
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() as *const [T]) }
}
#[allow(clippy::mut_from_ref)]
#[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() }
}
}