pub struct Snatchable<T> {
value: UnsafeCell<Option<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<Option<T>>Implementations§
Source§impl<T> Snatchable<T>
impl<T> Snatchable<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.
Trait Implementations§
Source§impl<T> Debug for Snatchable<T>
impl<T> Debug for Snatchable<T>
impl<T> Sync for Snatchable<T>
Auto Trait Implementations§
impl<T> !Freeze for Snatchable<T>
impl<T> !RefUnwindSafe for Snatchable<T>
impl<T> Send for Snatchable<T>where
T: Send,
impl<T> Unpin for Snatchable<T>where
T: Unpin,
impl<T> UnwindSafe for Snatchable<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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more