use crate::ExceptionFree;
use core::cell::{RefCell, RefMut};
#[derive(Default)]
#[cfg_attr(
feature = "zerocopy",
derive(
zerocopy::FromBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
zerocopy::Unaligned
)
)]
#[repr(transparent)]
pub struct ExceptionLock<T> {
value: T,
}
impl<T> ExceptionLock<T> {
pub const fn new(value: T) -> Self {
Self { value }
}
pub fn borrow<'cs>(&'cs self, _: ExceptionFree<'cs>) -> &'cs T {
&self.value
}
pub fn into_inner(self) -> T {
self.value
}
}
impl<T> ExceptionLock<RefCell<T>> {
pub fn borrow_mut<'cs>(&'cs self, token: ExceptionFree<'cs>) -> RefMut<'cs, T> {
self.borrow(token).borrow_mut()
}
pub fn as_ptr(&self) -> *mut T {
self.value.as_ptr()
}
}