Struct MappedRwLockWriteGuard

#[must_use = "if unused the RwLock will immediately unlock"]
pub struct MappedRwLockWriteGuard<'rwlock, T: ?Sized + 'rwlock> { pub(in ::sync::nonpoison::rwlock) data: NonNull<T>, pub(in ::sync::nonpoison::rwlock) _variance: PhantomData<&'rwlock mut T>, pub(in ::sync::nonpoison::rwlock) inner_lock: &'rwlock RwLock }

RAII structure used to release the exclusive write access of a lock when dropped, which can point to a subfield of the protected data.

This structure is created by the map and filter_map methods on RwLockWriteGuard.

Fields

data: NonNull<T>

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 MappedRwLockWriteGuard instance only holds uniquneness until it drops, not for its whole scope. NonNull is preferable over *const T to allow for niche optimizations.

_variance: PhantomData<&'rwlock mut T>

NonNull is covariant over T, so we add a PhantomData<&'rwlock mut T> field here to enforce the correct invariance over T.

inner_lock: &'rwlock RwLock

A reference to the internal sys::RwLock that we have write-locked.

Implementations

impl<'rwlock, T: ?Sized> MappedRwLockWriteGuard<'rwlock, T>

fn map<U, F>(orig: Self, f: F) -> MappedRwLockWriteGuard<'rwlock, U>
where
    F: FnOnce(&mut T) -> &mut U,
    U: ?Sized,

Makes a MappedRwLockWriteGuard for a component of the borrowed data, e.g. an enum variant.

The RwLock is already locked for writing, so this cannot fail.

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

Panics

If the closure panics, the guard will be dropped (unlocked).

fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'rwlock, U>, Self>
where
    F: FnOnce(&mut T) -> Option<&mut U>,
    U: ?Sized,

Makes a MappedRwLockWriteGuard 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 writing, so this cannot fail.

This is an associated function that needs to be used as MappedRwLockWriteGuard::filter_map(...). A method would interfere with methods of the same name on the contents of the MappedRwLockWriteGuard used through Deref.

Panics

If the closure panics, the guard will be dropped (unlocked).

Trait Implementations

impl<T: ?Sized + Debug> Debug for MappedRwLockWriteGuard<'_, T>

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

impl<T: ?Sized + Display> Display for MappedRwLockWriteGuard<'_, T>

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

impl<T: ?Sized + Sync> Sync for MappedRwLockWriteGuard<'_, T>

impl<T: ?Sized> !Send for MappedRwLockWriteGuard<'_, T>

impl<T: ?Sized> Deref for MappedRwLockWriteGuard<'_, T>

type Target = T;
fn deref(&self) -> &T

impl<T: ?Sized> DerefMut for MappedRwLockWriteGuard<'_, T>

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

impl<T: ?Sized> Drop for MappedRwLockWriteGuard<'_, T>

fn drop(&mut self)

Auto Trait Implementations

impl<'rwlock, T> !UnwindSafe for MappedRwLockWriteGuard<'rwlock, T>

impl<'rwlock, T> Freeze for MappedRwLockWriteGuard<'rwlock, T> where NonNull<T>: Freeze, PhantomData<&'rwlock mut T>: Freeze, T: ?Sized,

impl<'rwlock, T> RefUnwindSafe for MappedRwLockWriteGuard<'rwlock, T> where NonNull<T>: RefUnwindSafe, PhantomData<&'rwlock mut T>: RefUnwindSafe, T: ?Sized,

impl<'rwlock, T> Unpin for MappedRwLockWriteGuard<'rwlock, T> where NonNull<T>: Unpin, PhantomData<&'rwlock mut T>: Unpin, T: ?Sized,

impl<'rwlock, T> UnsafeUnpin for MappedRwLockWriteGuard<'rwlock, T> where NonNull<T>: UnsafeUnpin, PhantomData<&'rwlock mut T>: UnsafeUnpin, T: ?Sized,

Blanket Implementations

impl<P, T> Receiver for MappedRwLockWriteGuard<'rwlock, T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for MappedRwLockWriteGuard<'rwlock, T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for MappedRwLockWriteGuard<'rwlock, T> where T: ?Sized,

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

impl<T> From<T> for MappedRwLockWriteGuard<'rwlock, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for MappedRwLockWriteGuard<'rwlock, T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for MappedRwLockWriteGuard<'rwlock, T>

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

fn to_string(&self) -> String

impl<T, U> Into<U> for MappedRwLockWriteGuard<'rwlock, T> where U: From<T>,

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, U> TryFrom<U> for MappedRwLockWriteGuard<'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 MappedRwLockWriteGuard<'rwlock, T> where U: TryFrom<T>,

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