[][src]Struct fast_async_mutex::mutex_unordered::UnorderedMutex

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

An async unordered mutex. It will be works with any async runtime in Rust, it may be a tokio, smol, async-std and etc..

The main difference with the standard Mutex is unordered mutex will not check an ordering of blocking. This way is much faster, but there are some risks what someone mutex lock will be executed much later.

Implementations

impl<T> UnorderedMutex<T>[src]

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

Create a new UnorderedMutex

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

Notable traits for UnorderedMutexGuardFuture<'a, T>

impl<'a, T: ?Sized> Future for UnorderedMutexGuardFuture<'a, T> type Output = UnorderedMutexGuard<'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_unordered::UnorderedMutex;

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

pub fn lock_owned(self: &Arc<Self>) -> UnorderedMutexOwnedGuardFuture<T>[src]

Acquires the mutex.

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

Examples

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

Trait Implementations

impl<T: Debug> Debug for UnorderedMutex<T>[src]

impl<T: ?Sized + Send> Send for UnorderedMutex<T>[src]

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for UnorderedMutex<T>

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

impl<T: ?Sized> UnwindSafe for UnorderedMutex<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.