Struct Mutex
pub struct Mutex<T: ?Sized> { /* private fields */ }
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>
const fn new(t: T) -> SelfCreates a new futures-aware mutex.
fn into_inner(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) -> 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) -> 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(&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;
Trait Implementations
impl<T> From<T> for Mutex<T>
fn from(t: T) -> Self
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, f: &mut Formatter<'_>) -> Result
impl<T: Default> Default for Mutex<T>
fn default() -> Self
Auto Trait Implementations
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>
where
UnsafeCell<T>: Unpin,
T: ?Sized,
impl<T> UnsafeUnpin for Mutex<T>
where
UnsafeCell<T>: UnsafeUnpin,
T: ?Sized,
impl<T> UnwindSafe for Mutex<T>
where
UnsafeCell<T>: UnwindSafe,
T: ?Sized,
Blanket Implementations
impl<T> Any for Mutex<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Mutex<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Mutex<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Mutex<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Mutex<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Mutex<T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Mutex<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>