use std::cell::UnsafeCell;
use crate::marker::ThreadBound;
#[repr(transparent)]
pub struct RawCell<T> {
value: UnsafeCell<T>,
_thread: ThreadBound,
}
impl<T> RawCell<T> {
pub const fn new(value: T) -> Self {
Self {
value: UnsafeCell::new(value),
_thread: ThreadBound::NEW,
}
}
pub unsafe fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R {
f(unsafe { &*self.value.get() })
}
pub unsafe fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
f(unsafe { &mut *self.value.get() })
}
pub fn get_mut(&mut self) -> &mut T {
self.value.get_mut()
}
}