pub struct Mutex<T> { /* private fields */ }
Available on crate feature
sync
only.Expand description
An asynchronous mutual exclusion primitive useful for protecting shared data
Each mutex has a type parameter (T
) which represents the data that it is protecting. The data
can only be accessed through the RAII guards returned from lock
, which
guarantees that the data is only ever accessed when the mutex is locked.
Implementations§
Source§impl<T> Mutex<T>
impl<T> Mutex<T>
Sourcepub async fn lock(&self) -> MutexGuard<'_, T>
pub async fn lock(&self) -> MutexGuard<'_, T>
A future that resolves on acquiring the lock and returns the MutexGuard
.
Sourcepub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError>
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError>
Try to acquire the lock
Trait Implementations§
impl<T> Send for Mutex<T>where
T: Send,
impl<T> Sync for Mutex<T>where
T: Send,
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>where
T: Unpin,
impl<T> !UnwindSafe for Mutex<T>
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
Mutably borrows from an owned value. Read more