#[repr(C, align(16))]pub struct Mutex<T: ?Sized> { /* private fields */ }Expand description
An mutual exclusive access lock for the interior data
Implementations§
Source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
Sourcepub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Try to lock the interior data for mutual exclusive access. Returns None if the lock failes
or Some(MutexGuard). The actual data, the MutexGuard wraps could be conviniently accessed by
dereferencing it.
§Example
static DATA: Mutex<u32> = Mutex::new(10);
if let Some(data) = DATA.try_lock() {
// do something with data
}Sourcepub fn lock(&self) -> MutexGuard<'_, T>
pub fn lock(&self) -> MutexGuard<'_, T>
Lock the guarded data for mutual exclusive access. This blocks until the data could be
successfully locked. The locked data will be returned as MutexGuard. Simply dereferencing
this allows access to the contained data value.
§Example
static DATA: Mutex<u32> = Mutex::new(10);
let mut data = DATA.lock();
// do something with data
*data = 15;
Sourcepub fn into_inner(self) -> Twhere
T: Sized,
pub fn into_inner(self) -> Twhere
T: Sized,
Consume the Mutex and return the inner value
Trait Implementations§
impl<T: ?Sized + Send> Sync for Mutex<T>
The Mutex is always Sync, to make it Send as well it need to be wrapped into an Arc.
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Send 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