Struct RwLockReadGuard

struct RwLockReadGuard<'a, T: ?Sized> { ... }

RAII structure used to release the shared read access of a lock when dropped.

This structure is created by the read method on RwLock.

Implementations

impl<'a, T: ?Sized> RwLockReadGuard<'a, T>

fn map<F, U: ?Sized>(this: Self, f: F) -> RwLockReadGuard<'a, U>
where
    F: FnOnce(&T) -> &U

Makes a new RwLockReadGuard for a component of the locked data.

This operation cannot fail as the RwLockReadGuard passed in already locked the data.

This is an associated function that needs to be used as RwLockReadGuard::map(...). A method would interfere with methods of the same name on the contents of the locked data.

This is an asynchronous version of RwLockReadGuard::map from the parking_lot crate.

Examples

use tokio::sync::{RwLock, RwLockReadGuard};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Foo(u32);

# #[tokio::main]
# async fn main() {
let lock = RwLock::new(Foo(1));

let guard = lock.read().await;
let guard = RwLockReadGuard::map(guard, |f| &f.0);

assert_eq!(1, *guard);
# }
fn try_map<F, U: ?Sized>(this: Self, f: F) -> Result<RwLockReadGuard<'a, U>, Self>
where
    F: FnOnce(&T) -> Option<&U>

Attempts to make a new RwLockReadGuard for a component of the locked data. The original guard is returned if the closure returns None.

This operation cannot fail as the RwLockReadGuard passed in already locked the data.

This is an associated function that needs to be used as RwLockReadGuard::try_map(..). A method would interfere with methods of the same name on the contents of the locked data.

This is an asynchronous version of RwLockReadGuard::try_map from the parking_lot crate.

Examples

use tokio::sync::{RwLock, RwLockReadGuard};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Foo(u32);

# #[tokio::main]
# async fn main() {
let lock = RwLock::new(Foo(1));

let guard = lock.read().await;
let guard = RwLockReadGuard::try_map(guard, |f| Some(&f.0)).expect("should not fail");

assert_eq!(1, *guard);
# }

impl<'a, T> Debug for RwLockReadGuard<'a, T>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'a, T> Display for RwLockReadGuard<'a, T>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'a, T> Freeze for RwLockReadGuard<'a, T>

impl<'a, T> RefUnwindSafe for RwLockReadGuard<'a, T>

impl<'a, T> Unpin for RwLockReadGuard<'a, T>

impl<'a, T> UnsafeUnpin for RwLockReadGuard<'a, T>

impl<'a, T> UnwindSafe for RwLockReadGuard<'a, T>

impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T>

fn drop(self: &mut Self)

impl<P, T> Receiver for RwLockReadGuard<'a, T>

impl<T> Any for RwLockReadGuard<'a, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RwLockReadGuard<'a, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for RwLockReadGuard<'a, T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for RwLockReadGuard<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Send for RwLockReadGuard<'_, T>

impl<T> Sync for RwLockReadGuard<'_, T>

impl<T> ToString for RwLockReadGuard<'a, T>

fn to_string(self: &Self) -> String

impl<T, U> Into for RwLockReadGuard<'a, T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for RwLockReadGuard<'a, T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for RwLockReadGuard<'a, T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>

fn deref(self: &Self) -> &T