Struct drone_core::sync::Mutex [−][src]
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]
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]
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);
Trait Implementations
impl<T: ?Sized + Debug> Debug for Mutex<T>
[src]
impl<T: ?Sized + Default> Default for Mutex<T>
[src]
impl<T> From<T> for Mutex<T>
[src]
fn from(data: T) -> Self
[src]
Creates a new mutex in an unlocked state ready for use. This is
equivalent to Mutex::new
.
impl<T: ?Sized + Send> Send for Mutex<T>
[src]
impl<T: ?Sized + Send> Sync for Mutex<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,