pub struct MutexGuard<'a, T: ?Sized + 'a> { /* private fields */ }Expand description
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
The data protected by the mutex can be accessed through this guard via its
Deref and DerefMut implementations.
This structure is created by the lock and try_lock methods on
Mutex.
Implementations§
Source§impl<'a, T: ?Sized> MutexGuard<'a, T>
impl<'a, T: ?Sized> MutexGuard<'a, T>
Sourcepub fn map<U, F>(orig: Self, f: F) -> MappedMutexGuard<'a, U>
🔬This is a nightly-only experimental API. (mapped_lock_guards #117108)
pub fn map<U, F>(orig: Self, f: F) -> MappedMutexGuard<'a, U>
mapped_lock_guards #117108)Makes a MappedMutexGuard for a component of the borrowed data, e.g.
an enum variant.
The Mutex is already locked, so this cannot fail.
This is an associated function that needs to be used as
MutexGuard::map(...). A method would interfere with methods of the
same name on the contents of the MutexGuard used through Deref.
Sourcepub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
🔬This is a nightly-only experimental API. (mapped_lock_guards #117108)
pub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
mapped_lock_guards #117108)Makes a MappedMutexGuard for a component of the borrowed data. The
original guard is returned as an Err(...) if the closure returns
None.
The Mutex is already locked, so this cannot fail.
This is an associated function that needs to be used as
MutexGuard::try_map(...). A method would interfere with methods of the
same name on the contents of the MutexGuard used through Deref.