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

A guard wrapping a live reference into a left-right protected T.

As long as this guard lives, the T being read cannot change. If a writer attempts to call WriteHandle::publish, that call will block until this guard is dropped.

To scope the guard to a subset of the data in T, use map and try_map.

Implementations

Makes a new ReadGuard for a component of the borrowed data.

This is an associated function that needs to be used as ReadGuard::map(...), since a method would interfere with methods of the same name on the contents of a Readguard used through Deref.

Examples
use left_right::{ReadGuard, ReadHandle};

fn get_str(handle: &ReadHandle<Vec<(String, i32)>>, i: usize) -> Option<ReadGuard<'_, str>> {
    handle.enter().map(|guard| {
        ReadGuard::map(guard, |t| {
            &*t[i].0
        })
    })
}

Makes a new ReadGuard for a component of the borrowed data that may not exist.

This method differs from map in that it drops the guard if the closure maps to None. This allows you to “lift” a ReadGuard<Option<T>> into an Option<ReadGuard<T>>.

This is an associated function that needs to be used as ReadGuard::try_map(...), since a method would interfere with methods of the same name on the contents of a Readguard used through Deref.

Examples
use left_right::{ReadGuard, ReadHandle};

fn try_get_str(handle: &ReadHandle<Vec<(String, i32)>>, i: usize) -> Option<ReadGuard<'_, str>> {
    handle.enter().and_then(|guard| {
        ReadGuard::try_map(guard, |t| {
            t.get(i).map(|v| &*v.0)
        })
    })
}

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. 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.

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.