pub struct MutexGuard<'a, T>where
T: 'a + ?Sized,{ /* private fields */ }展开描述
An RAII implementation of 一个 “scoped lock” of 一个 mutex. When this structure is dropped (falls out of scope), the lock , unlocked.
此 data protected by the mutex can be accessed through this guard via its
Deref 并 DerefMut implementations.
This structure is created by the lock 并 try_lock methods on
Mutex。
实现§
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 一个 MappedMutexGuard 用于 一个 component of the borrowed data, e.g.
an enum variant.
此 Mutex is already locked, so this cannot fail.
This 是 associated function that needs 到 be 用 as
MutexGuard::map(。。。)。 A method would interfere with methods of the
same name on the contents of the MutexGuard 用 through Deref。
Sourcepub fn filter_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 filter_map<U, F>( orig: MutexGuard<'a, T>, f: F, ) -> Result<MappedMutexGuard<'a, U>, MutexGuard<'a, T>>
mapped_lock_guards)Makes 一个 MappedMutexGuard 用于 一个 component of the borrowed data. 此
original guard is returned as an Err(。。。) if the closure returns
None。
此 Mutex is already locked, so this cannot fail.
This 是 associated function that needs 到 be 用 as
MutexGuard::filter_map(。。。)。 A method would interfere with methods of the
same name on the contents of the MutexGuard 用 through Deref。
Trait 实现§
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,
A MutexGuard is not Send 到 maximize platform portability.
On platforms that use POSIX threads (commonly referred 到 as pthreads) there 是 requirement 到
release mutex locks on the same thread they were acquired.
For this reason, MutexGuard must not implement Send 到 prevent it being dropped 从
another thread.
impl<T> Sync for MutexGuard<'_, T>
T must be Sync 用于 一个 MutexGuard<T> 到 be Sync
because it is possible 到 get 一个 &T 从 &MutexGuard (via Deref)。