pub struct RwLockUpgradableReadGuard<'a, T: ?Sized> { /* private fields */ }
Expand description

A guard that releases the upgradable read lock when dropped.

Implementations

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());

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();

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;

Trait Implementations

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.