Struct sp_std::sync::MutexGuard
1.0.0 · source · pub struct MutexGuard<'a, T>where
T: 'a + ?Sized,{ /* 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> MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> MutexGuard<'a, T>where
T: ?Sized,
sourcepub fn map<U, F>(orig: MutexGuard<'a, T>, f: F) -> MappedMutexGuard<'a, U>
🔬This is a nightly-only experimental API. (mapped_lock_guards
)
pub fn map<U, F>(orig: MutexGuard<'a, T>, f: F) -> MappedMutexGuard<'a, U>
mapped_lock_guards
)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: MutexGuard<'a, T>,
f: F,
) -> Result<MappedMutexGuard<'a, U>, MutexGuard<'a, T>>
🔬This is a nightly-only experimental API. (mapped_lock_guards
)
pub fn try_map<U, F>( orig: MutexGuard<'a, T>, f: F, ) -> Result<MappedMutexGuard<'a, U>, MutexGuard<'a, T>>
mapped_lock_guards
)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
.