pub struct SnatchableInner<T> {
value: UnsafeCell<T>,
}Expand description
A value that is mostly immutable but can be “snatched” if we need to destroy it early.
In order to safely access the underlying data, the device’s global snatchable lock must be taken. To guarantee it, methods take a read or write guard of that special lock.
Fields§
§value: UnsafeCell<T>Implementations§
Source§impl<T> SnatchableInner<Option<T>>
impl<T> SnatchableInner<Option<T>>
pub fn new(val: T) -> Self
pub fn empty() -> Self
Sourcepub fn get<'a>(&'a self, _guard: &'a SnatchGuard<'_>) -> Option<&'a T>
pub fn get<'a>(&'a self, _guard: &'a SnatchGuard<'_>) -> Option<&'a T>
Get read access to the value. Requires a the snatchable lock’s read guard.
Sourcepub fn snatch(&self, _guard: &mut ExclusiveSnatchGuard<'_>) -> Option<T>
pub fn snatch(&self, _guard: &mut ExclusiveSnatchGuard<'_>) -> Option<T>
Take the value. Requires a the snatchable lock’s write guard.
Source§impl<T> SnatchableInner<DestructibleResourceState<T>>
impl<T> SnatchableInner<DestructibleResourceState<T>>
pub fn new(val: T) -> Self
pub fn invalid() -> Self
Sourcepub fn get<'a>(
&'a self,
_guard: &'a SnatchGuard<'_>,
) -> DestructibleResourceState<&'a T>
pub fn get<'a>( &'a self, _guard: &'a SnatchGuard<'_>, ) -> DestructibleResourceState<&'a T>
Get read access to the value. Requires a the snatchable lock’s read guard.
Sourcepub fn snatch(
&self,
_guard: &mut ExclusiveSnatchGuard<'_>,
) -> DestructibleResourceState<T>
pub fn snatch( &self, _guard: &mut ExclusiveSnatchGuard<'_>, ) -> DestructibleResourceState<T>
Take the value. Requires a the snatchable lock’s write guard.
Sourcepub fn take(&mut self) -> DestructibleResourceState<T>
pub fn take(&mut self) -> DestructibleResourceState<T>
Take the value without a guard. This can only be used with exclusive access to self, so it does not require locking.
Typically useful in a drop implementation.
Trait Implementations§
Source§impl<T> Debug for SnatchableInner<T>
impl<T> Debug for SnatchableInner<T>
impl<T> Sync for SnatchableInner<T>
Auto Trait Implementations§
impl<T> !Freeze for SnatchableInner<T>
impl<T> !RefUnwindSafe for SnatchableInner<T>
impl<T> Send for SnatchableInner<T>where
T: Send,
impl<T> Unpin for SnatchableInner<T>where
T: Unpin,
impl<T> UnsafeUnpin for SnatchableInner<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SnatchableInner<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more