Struct Mutex
struct Mutex<T: ?Sized> { ... }
A futures-aware mutex.
Fairness
This mutex provides no fairness guarantees. Tasks may not acquire the mutex in the order that they requested the lock, and it's possible for a single task which repeatedly takes the lock to starve other tasks, which may be left waiting indefinitely.
Implementations
impl<T> Mutex<T>
fn new(t: T) -> SelfCreates a new futures-aware mutex.
fn into_inner(self: Self) -> TConsumes this mutex, returning the underlying data.
Examples
use Mutex; let mutex = new; assert_eq!;
impl<T: ?Sized> Mutex<T>
fn try_lock(self: &Self) -> Option<MutexGuard<'_, T>>Attempt to acquire the lock immediately.
If the lock is currently held, this will return
None.fn try_lock_owned(self: &Arc<Self>) -> Option<OwnedMutexGuard<T>>Attempt to acquire the lock immediately.
If the lock is currently held, this will return
None.fn lock(self: &Self) -> MutexLockFuture<'_, T>Acquire the lock asynchronously.
This method returns a future that will resolve once the lock has been successfully acquired.
fn lock_owned(self: Arc<Self>) -> OwnedMutexLockFuture<T>Acquire the lock asynchronously.
This method returns a future that will resolve once the lock has been successfully acquired.
fn get_mut(self: &mut Self) -> &mut TReturns a mutable reference to the underlying data.
Since this call borrows the
Mutexmutably, no actual locking needs to take place -- the mutable borrow statically guarantees no locks exist.Examples
# block_on;
impl<T> Any for Mutex<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Mutex<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Mutex<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Freeze for Mutex<T>
impl<T> From for Mutex<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> From for Mutex<T>
fn from(t: never) -> T
impl<T> From for Mutex<T>
fn from(t: T) -> Self
impl<T> RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>
impl<T> UnsafeUnpin for Mutex<T>
impl<T> UnwindSafe for Mutex<T>
impl<T, U> Into for Mutex<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Mutex<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Mutex<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: ?Sized + Send> Send for Mutex<T>
impl<T: ?Sized + Send> Sync for Mutex<T>
impl<T: ?Sized> Debug for Mutex<T>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<T: Default> Default for Mutex<T>
fn default() -> Self