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
)Available on crate feature std
only.
pub fn map<U, F>(orig: MutexGuard<'a, T>, f: F) -> MappedMutexGuard<'a, U>
mapped_lock_guards
)std
only.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
)Available on crate feature std
only.
pub fn try_map<U, F>( orig: MutexGuard<'a, T>, f: F, ) -> Result<MappedMutexGuard<'a, U>, MutexGuard<'a, T>>
mapped_lock_guards
)std
only.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
.
Trait Implementations§
1.16.0 · Source§impl<T> Debug for MutexGuard<'_, T>
impl<T> Debug for MutexGuard<'_, T>
1.0.0 · Source§impl<T> Deref for MutexGuard<'_, T>where
T: ?Sized,
impl<T> Deref for MutexGuard<'_, T>where
T: ?Sized,
1.0.0 · Source§impl<T> DerefMut for MutexGuard<'_, T>where
T: ?Sized,
impl<T> DerefMut for MutexGuard<'_, T>where
T: ?Sized,
1.20.0 · Source§impl<T> Display for MutexGuard<'_, T>
impl<T> Display for MutexGuard<'_, T>
1.0.0 · Source§impl<T> Drop for MutexGuard<'_, T>where
T: ?Sized,
impl<T> Drop for MutexGuard<'_, T>where
T: ?Sized,
impl<T> !Send for MutexGuard<'_, T>where
T: ?Sized,
impl<T> Sync for MutexGuard<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> Unpin for MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for MutexGuard<'a, T>where
T: ?Sized,
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
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.