Struct async_std::sync::RwLockUpgradableReadGuard
source · pub struct RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,{ /* private fields */ }
Expand description
A guard that releases the upgradable read lock when dropped.
Implementations§
source§impl<'a, T> RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
impl<'a, T> RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
sourcepub fn downgrade(
guard: RwLockUpgradableReadGuard<'a, T>,
) -> RwLockReadGuard<'a, T>
pub fn downgrade( guard: RwLockUpgradableReadGuard<'a, T>, ) -> RwLockReadGuard<'a, T>
Downgrades into a regular reader guard.
§Examples
use async_lock::{RwLock, RwLockUpgradableReadGuard};
let lock = RwLock::new(1);
let reader = lock.upgradable_read().await;
assert_eq!(*reader, 1);
assert!(lock.try_upgradable_read().is_none());
let reader = RwLockUpgradableReadGuard::downgrade(reader);
assert!(lock.try_upgradable_read().is_some());
sourcepub fn try_upgrade(
guard: RwLockUpgradableReadGuard<'a, T>,
) -> Result<RwLockWriteGuard<'a, T>, RwLockUpgradableReadGuard<'a, T>>
pub fn try_upgrade( guard: RwLockUpgradableReadGuard<'a, T>, ) -> Result<RwLockWriteGuard<'a, T>, RwLockUpgradableReadGuard<'a, T>>
Attempts to upgrade into a write lock.
If a write lock could not be acquired at this time, then None
is returned. Otherwise,
an upgraded guard is returned that releases the write lock when dropped.
This function can only fail if there are other active read locks.
§Examples
use async_lock::{RwLock, RwLockUpgradableReadGuard};
let lock = RwLock::new(1);
let reader = lock.upgradable_read().await;
assert_eq!(*reader, 1);
let reader2 = lock.read().await;
let reader = RwLockUpgradableReadGuard::try_upgrade(reader).unwrap_err();
drop(reader2);
let writer = RwLockUpgradableReadGuard::try_upgrade(reader).unwrap();
sourcepub fn upgrade(guard: RwLockUpgradableReadGuard<'a, T>) -> Upgrade<'a, T> ⓘ
pub fn upgrade(guard: RwLockUpgradableReadGuard<'a, T>) -> Upgrade<'a, T> ⓘ
Upgrades into a write lock.
§Examples
use async_lock::{RwLock, RwLockUpgradableReadGuard};
let lock = RwLock::new(1);
let reader = lock.upgradable_read().await;
assert_eq!(*reader, 1);
let mut writer = RwLockUpgradableReadGuard::upgrade(reader).await;
*writer = 2;
sourcepub fn upgrade_blocking(
guard: RwLockUpgradableReadGuard<'a, T>,
) -> RwLockWriteGuard<'a, T>
pub fn upgrade_blocking( guard: RwLockUpgradableReadGuard<'a, T>, ) -> RwLockWriteGuard<'a, T>
Upgrades into a write lock.
§Blocking
This function will block the current thread until it is able to acquire the write lock.
§Examples
use async_lock::{RwLock, RwLockUpgradableReadGuard};
let lock = RwLock::new(1);
let reader = lock.upgradable_read_blocking();
assert_eq!(*reader, 1);
let mut writer = RwLockUpgradableReadGuard::upgrade_blocking(reader);
*writer = 2;
Trait Implementations§
source§impl<T> Debug for RwLockUpgradableReadGuard<'_, T>
impl<T> Debug for RwLockUpgradableReadGuard<'_, T>
source§impl<T> Deref for RwLockUpgradableReadGuard<'_, T>where
T: ?Sized,
impl<T> Deref for RwLockUpgradableReadGuard<'_, T>where
T: ?Sized,
source§impl<T> Display for RwLockUpgradableReadGuard<'_, T>
impl<T> Display for RwLockUpgradableReadGuard<'_, T>
source§impl<'a, T> Drop for RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
impl<'a, T> Drop for RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
impl<T> Send for RwLockUpgradableReadGuard<'_, T>
impl<T> Sync for RwLockUpgradableReadGuard<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
impl<'a, T> !RefUnwindSafe for RwLockUpgradableReadGuard<'a, T>
impl<'a, T> Unpin for RwLockUpgradableReadGuard<'a, T>where
T: ?Sized,
impl<'a, T> !UnwindSafe for RwLockUpgradableReadGuard<'a, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more