Struct drone_core::sync::Mutex [−][src]
pub struct Mutex<T: ?Sized> { /* fields omitted */ }
A mutual exclusion primitive useful for protecting shared data.
The mutex can be statically initialized or created via a new
constructor. Each mutex has a type parameter which represents the data that
it is protecting. The data can only be accessed through the RAII guards
returned from lock
and try_lock
, which guarantees that the data is
only ever accessed when the mutex is locked.
Implementations
impl<T> Mutex<T>
[src]
impl<T> Mutex<T>
[src]pub const fn new(data: T) -> Self
[src]
Creates a new mutex in an unlocked state ready for use.
Examples
use drone_core::sync::Mutex; let mutex = Mutex::new(0);
pub fn into_inner(self) -> T
[src]
Consumes this mutex, returning the underlying data.
Examples
use drone_core::sync::Mutex; let mutex = Mutex::new(0); assert_eq!(mutex.into_inner(), 0);
impl<T: ?Sized> Mutex<T>
[src]
impl<T: ?Sized> Mutex<T>
[src]pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
[src]
Attempts to acquire this lock immediately.
If the lock could not be acquired at this time, then None
is
returned. Otherwise, an RAII guard is returned. The lock will be
unlocked when the guard is dropped.
pub fn lock(&self) -> MutexLockFuture<'_, T>
[src]
Acquires this lock asynchronously.
This method returns a future that will resolve once the lock has been successfully acquired.
pub fn get_mut(&mut self) -> &mut T
[src]
Returns a mutable reference to the underlying data.
Since this call borrows the Mutex
mutably, no actual locking needs to
take place – the mutable borrow statically guarantees no locks exist.
Examples
use drone_core::sync::Mutex; let mut mutex = Mutex::new(0); *mutex.get_mut() = 10; assert_eq!(*mutex.try_lock().unwrap(), 10);