pub struct Mutex<T: ?Sized> { /* private fields */ }
Expand description
A mutual exclusion primitive useful for protecting shared data. Async version.
This mutex will block a task waiting for the lock to become available.
Implementations§
Source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
Sourcepub fn lock(&self) -> LockResult<MutexGuard<'_, T>>
pub fn lock(&self) -> LockResult<MutexGuard<'_, T>>
Acquire the mutex, blocking the current thread until it is able to do so.
This is a sync version, and calling it from an async task will possibly block the async work thread, potentially causing deadlock.
Sourcepub async fn lock_async(&self) -> LockResult<MutexGuard<'_, T>>
pub async fn lock_async(&self) -> LockResult<MutexGuard<'_, T>>
Aquire the mutex, async version.
Sourcepub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>>
pub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>>
Attempt to aquire the lock.
Trait Implementations§
impl<T: ?Sized + Send> Send for Mutex<T>
impl<T: ?Sized + Send> Sync for Mutex<T>
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>
impl<T> UnwindSafe for Mutex<T>where
T: UnwindSafe + ?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
Mutably borrows from an owned value. Read more