pub struct SharedGuard<'a, T: ?Sized> { /* private fields */ }Expand description
Resource object that grants shared access to guarded data of type T.
Implementations§
Sourcepub fn map<U>(guard: Self, f: impl FnOnce(&T) -> &U) -> SharedGuard<'a, U>where
U: ?Sized,
pub fn map<U>(guard: Self, f: impl FnOnce(&T) -> &U) -> SharedGuard<'a, U>where
U: ?Sized,
Converts a SharedGuard<T> into a SharedGuard<U> by applying a
projection function to select a sub-component of the guarded data.
The SharedGuard<U> this produces will keep the whole T locked for
shared access, but won’t be able to access anything but the chosen
sub-component U.
By transforming an existing reader, this leaves the reader count unchanged.
Sourcepub fn map_split<U, V>(
guard: Self,
f: impl FnOnce(&T) -> (&U, &V),
) -> (SharedGuard<'a, U>, SharedGuard<'a, V>)
pub fn map_split<U, V>( guard: Self, f: impl FnOnce(&T) -> (&U, &V), ) -> (SharedGuard<'a, U>, SharedGuard<'a, V>)
Converts a SharedGuard<T> into a pair SharedGuard<U> and
SharedGuard<V> by applying a projection function to select two
sub-components of the guarded data.
Both of the returned guards will keep the whole T locked for shared
access, but won’t be able to access access anything but the chosen
sub-components U and V (respectively).
This increases the total reader count of the lock by 1.
§Panics
There is a maximum number of supported readers on a lock, which is at
least usize::MAX/2. This number is very difficult to reach in
non-pathological code. However, if you reach it by splitting a reader,
this will panic.