use std::marker::PhantomData;
#[derive(Debug)]
pub(crate) struct UnsafeCell<T> {
_marker: PhantomData<*const ()>,
inner: std::cell::UnsafeCell<T>,
}
impl<T> UnsafeCell<T> {
#[inline]
pub(crate) const fn new(data: T) -> UnsafeCell<T> {
UnsafeCell {
inner: std::cell::UnsafeCell::new(data),
_marker: PhantomData,
}
}
#[inline]
pub(crate) unsafe fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R {
f(&*self.inner.get())
}
#[inline]
pub(crate) unsafe fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
f(&mut *self.inner.get())
}
}