pub struct RwLockReadGuard<'rwlock, T: ?Sized + 'rwlock> {
data: NonNull<T>,
inner_lock: &'rwlock RwLock,
}
nonpoison_rwlock
#134645)Expand description
Fields§
§data: NonNull<T>
nonpoison_rwlock
#134645)A pointer to the data protected by the RwLock
. Note that we use a pointer here instead of
&'rwlock T
to avoid noalias
violations, because a RwLockReadGuard
instance only holds
immutability until it drops, not for its whole scope.
NonNull
is preferable over *const T
to allow for niche optimizations. NonNull
is also
covariant over T
, just like we would have with &T
.
inner_lock: &'rwlock RwLock
nonpoison_rwlock
#134645)A reference to the internal sys::RwLock
that we have read-locked.
Implementations§
Source§impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T>
impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T>
Sourceunsafe fn new(lock: &'rwlock RwLock<T>) -> RwLockReadGuard<'rwlock, T>
🔬This is a nightly-only experimental API. (sync_nonpoison
#134645)
unsafe fn new(lock: &'rwlock RwLock<T>) -> RwLockReadGuard<'rwlock, T>
sync_nonpoison
#134645)Creates a new instance of RwLockReadGuard<T>
from a RwLock<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()
, or lock.inner.downgrade()
before
instantiating this object.
Sourcepub fn map<U, F>(orig: Self, f: F) -> MappedRwLockReadGuard<'rwlock, U>
🔬This is a nightly-only experimental API. (mapped_lock_guards
#117108)
pub fn map<U, F>(orig: Self, f: F) -> MappedRwLockReadGuard<'rwlock, U>
mapped_lock_guards
#117108)Makes a MappedRwLockReadGuard
for a component of the borrowed data, e.g.
an enum variant.
The RwLock
is 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 the RwLockReadGuard
used through
Deref
.
§Panics
If the closure panics, the guard will be dropped (unlocked).
Sourcepub fn filter_map<U, F>(
orig: Self,
f: F,
) -> Result<MappedRwLockReadGuard<'rwlock, U>, Self>
🔬This is a nightly-only experimental API. (mapped_lock_guards
#117108)
pub fn filter_map<U, F>( orig: Self, f: F, ) -> Result<MappedRwLockReadGuard<'rwlock, U>, Self>
mapped_lock_guards
#117108)Makes a MappedRwLockReadGuard
for a component of the borrowed data. The
original guard is returned as an Err(...)
if the closure returns
None
.
The RwLock
is 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 the RwLockReadGuard
used through
Deref
.
§Panics
If the closure panics, the guard will be dropped (unlocked).
Trait Implementations§
Source§impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>
impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>
Source§impl<T: ?Sized> Drop for RwLockReadGuard<'_, T>
impl<T: ?Sized> Drop for RwLockReadGuard<'_, T>
impl<T: ?Sized> !Send for RwLockReadGuard<'_, T>
impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'_, T>
Auto Trait Implementations§
impl<'rwlock, T> Freeze for RwLockReadGuard<'rwlock, T>where
T: ?Sized,
impl<'rwlock, T> RefUnwindSafe for RwLockReadGuard<'rwlock, T>where
T: RefUnwindSafe + ?Sized,
impl<'rwlock, T> Unpin for RwLockReadGuard<'rwlock, T>where
T: ?Sized,
impl<'rwlock, T> UnwindSafe for RwLockReadGuard<'rwlock, T>where
T: RefUnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more