pub struct MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock, T: ?Sized,
{ /* private fields */ }
Expand description

An RAII read lock guard returned by RwLockReadGuard::map, which can point to a subfield of the protected data.

The main difference between MappedRwLockReadGuard and RwLockReadGuard is that the former doesn’t support temporarily unlocking and re-locking, since that could introduce soundness issues if the locked object is modified by another thread.

Implementations§

§

impl<'a, R, T> MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: 'a + ?Sized,

pub fn map<U, F>( s: MappedRwLockReadGuard<'a, R, T>, f: F, ) -> MappedRwLockReadGuard<'a, R, U>
where F: FnOnce(&T) -> &U, U: ?Sized,

Make a new MappedRwLockReadGuard for a component of the locked data.

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

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

pub fn try_map<U, F>( s: MappedRwLockReadGuard<'a, R, T>, f: F, ) -> Result<MappedRwLockReadGuard<'a, R, U>, MappedRwLockReadGuard<'a, R, T>>
where F: FnOnce(&T) -> Option<&U>, U: ?Sized,

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

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

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

§

impl<'a, R, T> MappedRwLockReadGuard<'a, R, T>
where R: RawRwLockFair + 'a, T: 'a + ?Sized,

pub fn unlock_fair(s: MappedRwLockReadGuard<'a, R, T>)

Unlocks the RwLock using a fair unlock protocol.

By default, RwLock is unfair and allow the current thread to re-lock the RwLock before another has the chance to acquire the lock, even if that thread has been blocked on the RwLock for a long time. This is the default because it allows much higher throughput as it avoids forcing a context switch on every RwLock unlock. This can result in one thread acquiring a RwLock many more times than other threads.

However in some cases it can be beneficial to ensure fairness by forcing the lock to pass on to a waiting thread if there is one. This is done by using this method instead of dropping the MappedRwLockReadGuard normally.

Trait Implementations§

§

impl<'a, R, T> Debug for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: Debug + 'a + ?Sized,

§

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

Formats the value using the given formatter. Read more
§

impl<'a, R, T> Deref for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: 'a + ?Sized,

§

type Target = T

The resulting type after dereferencing.
§

fn deref(&self) -> &T

Dereferences the value.
§

impl<'a, R, T> Display for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: Display + 'a + ?Sized,

§

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

Formats the value using the given formatter. Read more
§

impl<'a, R, T> Drop for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: 'a + ?Sized,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<'a, R, T> Send for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: Sync + 'a + ?Sized, <R as RawRwLock>::GuardMarker: Send,

§

impl<'a, R, T> Sync for MappedRwLockReadGuard<'a, R, T>
where R: RawRwLock + 'a, T: Sync + 'a + ?Sized,

Auto Trait Implementations§

§

impl<'a, R, T> Freeze for MappedRwLockReadGuard<'a, R, T>
where T: ?Sized,

§

impl<'a, R, T> RefUnwindSafe for MappedRwLockReadGuard<'a, R, T>

§

impl<'a, R, T> Unpin for MappedRwLockReadGuard<'a, R, T>
where T: ?Sized,

§

impl<'a, R, T> UnwindSafe for MappedRwLockReadGuard<'a, R, T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> RawDrop for T

§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V