pub struct CryoMut<'a, T: ?Sized + 'a> { /* private fields */ }
Expand description
A cell-like type that enforces the lifetime restriction of its borrowed value at runtime.
CryoMut
is a variation of Cryo
that can be mutably borrowed.
When a CryoMut
is dropped, the current thread will be blocked until all
references to the contained value are dropped. This ensures that none of
the references can outlive the referent.
See the module-level documentation for more details.
Implementations
sourceimpl<'a, T: ?Sized + 'a> CryoMut<'a, T>
impl<'a, T: ?Sized + 'a> CryoMut<'a, T>
sourcepub unsafe fn new(x: &'a mut T) -> Self
pub unsafe fn new(x: &'a mut T) -> Self
Construct a new CryoMut
.
Safety
-
The constructed
CryoMut
must not be moved around. This might result in a dangling pointer inCryoMut*Guard
. -
The constructed
CryoMut
must not be disposed without dropping (e.g., passed tostd::mem::forget
). This might result in a dangling pointer inCryoMut*Guard
.
sourcepub fn read(&self) -> CryoMutReadGuard<T>
pub fn read(&self) -> CryoMutReadGuard<T>
Acquire a read (shared) lock on a CryoMut
.
sourcepub fn try_read(&self) -> Option<CryoMutReadGuard<T>>
pub fn try_read(&self) -> Option<CryoMutReadGuard<T>>
Attempt to acquire a read (shared) lock on a CryoMut
.
sourcepub fn write(&self) -> CryoMutWriteGuard<T>
pub fn write(&self) -> CryoMutWriteGuard<T>
Acquire a write (exclusive) lock on a CryoMut
.
sourcepub fn try_write(&self) -> Option<CryoMutWriteGuard<T>>
pub fn try_write(&self) -> Option<CryoMutWriteGuard<T>>
Attempt to acquire a write (exclusive) lock on a CryoMut
.
sourcepub fn try_get_mut(&mut self) -> Option<&mut T>
pub fn try_get_mut(&mut self) -> Option<&mut T>
Attempt to mutably borrow a CryoMut
using compile-time lifetime rules.
Returns None
if the CryoMut
is already borrowed via
CryoMutReadGuard
or CryoMutWriteGuard
.