[][src]Struct fast_async_mutex::rwlock::RwLock

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

The RW Lock mechanism accepts you get concurrent shared access to your data without waiting. And get unique access with locks like a Mutex.

Implementations

impl<T> RwLock<T>[src]

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

Create a new RWLock

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

pub fn write(&self) -> RwLockWriteGuardFuture<'_, T>

Notable traits for RwLockWriteGuardFuture<'a, T>

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

Acquires the mutex for are write.

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

Examples

use fast_async_mutex::rwlock::RwLock;

#[tokio::main]
async fn main() {
    let mutex = RwLock::new(10);
    let mut guard = mutex.write().await;
    *guard += 1;
    assert_eq!(*guard, 11);
}

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

Acquires the mutex for are write.

Returns a guard that releases the mutex and wake the next locker when it will be dropped. WriteLockOwnedGuard have a 'static lifetime, but requires the Arc<RWLock<T>> type

Examples

use fast_async_mutex::rwlock::RwLock;
use std::sync::Arc;
#[tokio::main]
async fn main() {
    let mutex = Arc::new(RwLock::new(10));
    let mut guard = mutex.write_owned().await;
    *guard += 1;
    assert_eq!(*guard, 11);
}

pub fn read(&self) -> RwLockReadGuardFuture<'_, T>

Notable traits for RwLockReadGuardFuture<'a, T>

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

Acquires the mutex for are read.

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

Examples

use fast_async_mutex::rwlock::RwLock;

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

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

Acquires the mutex for are write.

Returns a guard that releases the mutex and wake the next locker when it will be dropped. WriteLockOwnedGuard have a 'static lifetime, but requires the Arc<RWLock<T>> type

Examples

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

Trait Implementations

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

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

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for RwLock<T>

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

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