pub struct RwLock<T: ?Sized> { /* private fields */ }
Expand description
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§
Source§impl<T: ?Sized> RwLock<T>
impl<T: ?Sized> RwLock<T>
Sourcepub fn write(&self) -> RwLockWriteGuardFuture<'_, T> ⓘ
pub fn write(&self) -> RwLockWriteGuardFuture<'_, T> ⓘ
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);
}
Sourcepub fn write_owned(self: &Arc<Self>) -> RwLockWriteOwnedGuardFuture<T> ⓘ
pub fn write_owned(self: &Arc<Self>) -> RwLockWriteOwnedGuardFuture<T> ⓘ
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);
}
Sourcepub fn read(&self) -> RwLockReadGuardFuture<'_, T> ⓘ
pub fn read(&self) -> RwLockReadGuardFuture<'_, T> ⓘ
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);
}
Sourcepub fn read_owned(self: &Arc<Self>) -> RwLockReadOwnedGuardFuture<T> ⓘ
pub fn read_owned(self: &Arc<Self>) -> RwLockReadOwnedGuardFuture<T> ⓘ
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);
}