Struct std::sync::MutexGuard
1.0.0 · source · 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
.