use core::cell::UnsafeCell;
use core::ptr;
use super::chunk_mutator::ChunkMutator;
use super::chunk_ops::ChunkOps;
#[repr(transparent)]
pub(crate) struct CurrentChunk<C: ?Sized + ChunkOps>(UnsafeCell<ChunkMutator<C>>);
impl<C: ?Sized + ChunkOps> CurrentChunk<C> {
#[inline]
pub(crate) const fn new(mutator: ChunkMutator<C>) -> Self {
Self(UnsafeCell::new(mutator))
}
#[expect(clippy::inline_always, reason = "hot-path entry; must inline fully for arena performance")]
#[inline(always)]
pub(crate) fn borrow(&self) -> &ChunkMutator<C> {
unsafe { &*self.0.get() }
}
#[inline]
pub(crate) fn replace(&self, new: ChunkMutator<C>) -> ChunkMutator<C> {
unsafe {
let slot = self.0.get();
let prev = ptr::read(slot);
ptr::write(slot, new);
prev
}
}
#[inline]
#[cfg_attr(test, mutants::skip)] pub(crate) fn drop_replace(&self, new: ChunkMutator<C>) {
let _old = self.replace(new);
}
#[inline]
pub(crate) fn get_mut(&mut self) -> &mut ChunkMutator<C> {
self.0.get_mut()
}
}