[][src]Struct fast_async_mutex::mutex::Mutex

pub struct Mutex<T: ?Sized> { /* fields omitted */ }

The simple Mutex, which will provide unique access to you data between multiple threads/futures.

Implementations

impl<T> Mutex<T>[src]

pub const fn new(data: T) -> Mutex<T>[src]

Create a new Mutex

impl<T: ?Sized> Mutex<T>[src]

pub const fn lock(&self) -> MutexGuardFuture<'_, T>

Notable traits for MutexGuardFuture<'a, T>

impl<'a, T: ?Sized> Future for MutexGuardFuture<'a, T> type Output = MutexGuard<'a, T>;
[src]

Acquires the mutex.

Returns a guard that releases the mutex and wake the next locker when dropped.

Examples

use fast_async_mutex::mutex::Mutex;

#[tokio::main]
async fn main() {
    let mutex = Mutex::new(10);
    let guard = mutex.lock().await;
    assert_eq!(*guard, 10);
}

pub fn lock_owned(self: &Arc<Self>) -> MutexOwnedGuardFuture<T>

Notable traits for MutexOwnedGuardFuture<T>

impl<T: ?Sized> Future for MutexOwnedGuardFuture<T> type Output = MutexOwnedGuard<T>;
[src]

Acquires the mutex.

Returns a guard that releases the mutex and wake the next locker when dropped. MutexOwnedGuardFuture have a 'static lifetime, but requires the Arc<Mutex<T>> type

Examples

use fast_async_mutex::mutex::Mutex;
use std::sync::Arc;
#[tokio::main]
async fn main() {
    let mutex = Arc::new(Mutex::new(10));
    let guard = mutex.lock_owned().await;
    assert_eq!(*guard, 10);
}

Trait Implementations

impl<T: Debug + ?Sized> Debug for Mutex<T>[src]

impl<T: ?Sized> Send for Mutex<T> where
    T: Send
[src]

impl<T: ?Sized> Sync for Mutex<T> where
    T: Send + Sync
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Mutex<T>

impl<T: ?Sized> Unpin for Mutex<T> where
    T: Unpin

impl<T: ?Sized> UnwindSafe for Mutex<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.