pub struct Mutex<T: ?Sized> {
std: Mutex<T>,
}
Expand description
A mutual exclusion primitive useful for protecting shared data.
Fields§
§std: Mutex<T>
Implementations§
source§impl<T> Mutex<T>
impl<T> Mutex<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this mutex, returning the underlying data.
source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
sourcepub fn lock(&self) -> MutexGuard<'_, T>
pub fn lock(&self) -> MutexGuard<'_, T>
Acquires a mutex, blocking the current thread until it is able to do so.
This function will block the local thread until it is available to acquire the mutex. Upon returning, the thread is the only thread with the lock held. An RAII guard is returned to allow scoped unlock of the lock. When the guard goes out of scope, the mutex will be unlocked.
sourcepub fn try_lock(&self) -> Result<MutexGuard<'_, T>, WouldBlock>
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, WouldBlock>
Attempts to acquire this lock.
If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.
This function does not block.
Trait Implementations§
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for Mutex<T>
impl<T: ?Sized> Send for Mutex<T>where
T: Send,
impl<T: ?Sized> Sync for Mutex<T>where
T: Send,
impl<T: ?Sized> Unpin for Mutex<T>where
T: Unpin,
impl<T: ?Sized> 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