[−][src]Struct async_lock::RwLock
An async reader-writer lock.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(5); // Multiple read locks can be held at a time. let r1 = lock.read().await; let r2 = lock.read().await; assert_eq!(*r1, 5); assert_eq!(*r2, 5); drop((r1, r2)); // Only one write locks can be held at a time. let mut w = lock.write().await; *w += 1; assert_eq!(*w, 6);
Implementations
impl<T> RwLock<T>
[src]
pub fn new(t: T) -> RwLock<T>
[src]
pub fn into_inner(self) -> T
[src]
Unwraps the lock and returns the inner value.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(5); assert_eq!(lock.into_inner(), 5);
impl<T> RwLock<T> where
T: ?Sized,
[src]
T: ?Sized,
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>
[src]
Attempts to acquire a read lock.
If a read lock could not be acquired at this time, then None
is returned. Otherwise, a
guard is returned that releases the lock when dropped.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(1); let reader = lock.read().await; assert_eq!(*reader, 1); assert!(lock.try_read().is_some());
pub async fn read(&'_ self) -> RwLockReadGuard<'_, T>
[src]
Acquires a read lock.
Returns a guard that releases the lock when dropped.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(1); let reader = lock.read().await; assert_eq!(*reader, 1); assert!(lock.try_read().is_some());
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>
[src]
Attempts to acquire a write lock.
If a write lock could not be acquired at this time, then None
is returned. Otherwise, a
guard is returned that releases the lock when dropped.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(1); assert!(lock.try_write().is_some()); let reader = lock.read().await; assert!(lock.try_write().is_none());
pub async fn write(&'_ self) -> RwLockWriteGuard<'_, T>
[src]
Acquires a write lock.
Returns a guard that releases the lock when dropped.
Examples
use async_rwlock::RwLock; let lock = RwLock::new(1); let writer = lock.write().await; assert!(lock.try_read().is_none());
pub fn get_mut(&mut self) -> &mut T
[src]
Returns a mutable reference to the inner value.
Since this call borrows the lock mutably, no actual locking takes place. The mutable borrow statically guarantees no locks exist.
Examples
use async_rwlock::RwLock; let mut lock = RwLock::new(1); *lock.get_mut() = 2; assert_eq!(*lock.read().await, 2);
Trait Implementations
impl<T> Debug for RwLock<T> where
T: Debug + ?Sized,
[src]
T: Debug + ?Sized,
impl<T> Default for RwLock<T> where
T: Default + ?Sized,
[src]
T: Default + ?Sized,
impl<T> From<T> for RwLock<T>
[src]
impl<T> Send for RwLock<T> where
T: Send + ?Sized,
[src]
T: Send + ?Sized,
impl<T> Sync for RwLock<T> where
T: Send + Sync + ?Sized,
[src]
T: Send + Sync + ?Sized,
Auto Trait Implementations
impl<T> !RefUnwindSafe for RwLock<T>
impl<T: ?Sized> Unpin for RwLock<T> where
T: Unpin,
T: Unpin,
impl<T: ?Sized> UnwindSafe for RwLock<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,