Struct RwLockReadGuard
#[must_use = "if unused the RwLock will immediately unlock"]
pub struct RwLockReadGuard<'rwlock, T: ?Sized + 'rwlock> { pub(in ::sync::nonpoison::rwlock) data: NonNull<T>, pub(in ::sync::nonpoison::rwlock) inner_lock: &'rwlock RwLock }
RAII structure used to release the shared read access of a lock when dropped.
This structure is created by the read and try_read methods on
RwLock.
Fields
data: NonNull<T>A pointer to the data protected by the
RwLock. Note that we use a pointer here instead of&'rwlock Tto avoidnoaliasviolations, because aRwLockReadGuardinstance only holds immutability until it drops, not for its whole scope.NonNullis preferable over*const Tto allow for niche optimizations.NonNullis also covariant overT, just like we would have with&T.inner_lock: &'rwlock RwLockA reference to the internal
sys::RwLockthat we have read-locked.
Implementations
impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T>
unsafe fn new(lock: &'rwlock RwLock<T>) -> RwLockReadGuard<'rwlock, T>Creates a new instance of
RwLockReadGuard<T>from aRwLock<T>.Safety
This function is safe if and only if the same thread has successfully and safely called
lock.inner.read(),lock.inner.try_read(), orlock.inner.downgrade()before instantiating this object.fn map<U, F>(orig: Self, f: F) -> MappedRwLockReadGuard<'rwlock, U> where F: FnOnce(&T) -> &U, U: ?Sized,Makes a
MappedRwLockReadGuardfor a component of the borrowed data, e.g. an enum variant.The
RwLockis already locked for reading, so this cannot fail.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 theRwLockReadGuardused throughDeref.Panics
If the closure panics, the guard will be dropped (unlocked).
fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'rwlock, U>, Self> where F: FnOnce(&T) -> Option<&U>, U: ?Sized,Makes a
MappedRwLockReadGuardfor a component of the borrowed data. The original guard is returned as anErr(...)if the closure returnsNone.The
RwLockis already locked for reading, so this cannot fail.This is an associated function that needs to be used as
RwLockReadGuard::filter_map(...). A method would interfere with methods of the same name on the contents of theRwLockReadGuardused throughDeref.Panics
If the closure panics, the guard will be dropped (unlocked).
Trait Implementations
impl<T: ?Sized + Debug> Debug for RwLockReadGuard<'_, T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: ?Sized + Display> Display for RwLockReadGuard<'_, T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T>
impl<T: ?Sized> !Send for RwLockReadGuard<'_, T>
impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>
type Target = T;fn deref(&self) -> &T
impl<T: ?Sized> Drop for RwLockReadGuard<'_, T>
fn drop(&mut self)
Auto Trait Implementations
impl<'rwlock, T> Freeze for RwLockReadGuard<'rwlock, T>
where
NonNull<T>: Freeze,
T: ?Sized,
impl<'rwlock, T> RefUnwindSafe for RwLockReadGuard<'rwlock, T>
where
NonNull<T>: RefUnwindSafe,
T: ?Sized,
impl<'rwlock, T> Unpin for RwLockReadGuard<'rwlock, T>
where
NonNull<T>: Unpin,
T: ?Sized,
impl<'rwlock, T> UnsafeUnpin for RwLockReadGuard<'rwlock, T>
where
NonNull<T>: UnsafeUnpin,
T: ?Sized,
impl<'rwlock, T> UnwindSafe for RwLockReadGuard<'rwlock, T>
where
NonNull<T>: UnwindSafe,
T: ?Sized,
Blanket Implementations
impl<P, T> Receiver for RwLockReadGuard<'rwlock, T>
where
P: Deref<Target = T> + ?Sized,
T: ?Sized,
type Target = T;
impl<T> Any for RwLockReadGuard<'rwlock, T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for RwLockReadGuard<'rwlock, T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for RwLockReadGuard<'rwlock, T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for RwLockReadGuard<'rwlock, T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for RwLockReadGuard<'rwlock, T>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for RwLockReadGuard<'rwlock, T>
impl<T> ToString for RwLockReadGuard<'rwlock, T>
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for RwLockReadGuard<'rwlock, T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for RwLockReadGuard<'rwlock, T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for RwLockReadGuard<'rwlock, T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>