pub struct RwLockWriteGuard<'a, T: ?Sized> { /* private fields */ }Expand description
Exclusive access to a RwLock’s value; releases on drop. The release
makes the progress RwLockReadGuard’s does.
Implementations§
Source§impl<'a, T: ?Sized> RwLockWriteGuard<'a, T>
impl<'a, T: ?Sized> RwLockWriteGuard<'a, T>
Sourcepub fn map<F, U>(this: Self, f: F) -> RwLockMappedWriteGuard<'a, U>
pub fn map<F, U>(this: Self, f: F) -> RwLockMappedWriteGuard<'a, U>
A guard for a component of the locked data. It cannot fail: this guard already holds the write.
An associated function, RwLockWriteGuard::map(guard, f): a method
would shadow methods of the locked data.
Sourcepub fn downgrade_map<F, U>(this: Self, f: F) -> RwLockReadGuard<'a, U>
pub fn downgrade_map<F, U>(this: Self, f: F) -> RwLockReadGuard<'a, U>
A read guard for a component of the locked data, made while the
write is turned into a read in one step, as
downgrade does. Inside f the write is still
held, yet f is given only a &T: a &mut T could be kept past the
downgrade through interior mutability.
Sourcepub fn try_map<F, U>(
this: Self,
f: F,
) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
pub fn try_map<F, U>( this: Self, f: F, ) -> Result<RwLockMappedWriteGuard<'a, U>, Self>
map that gives the guard back when f finds no
component, with the write still held.
Sourcepub fn try_downgrade_map<F, U>(
this: Self,
f: F,
) -> Result<RwLockReadGuard<'a, U>, Self>
pub fn try_downgrade_map<F, U>( this: Self, f: F, ) -> Result<RwLockReadGuard<'a, U>, Self>
downgrade_map that gives the guard back when
f finds no component: the lock is then neither released nor
downgraded.
Sourcepub fn into_mapped(this: Self) -> RwLockMappedWriteGuard<'a, T>
pub fn into_mapped(this: Self) -> RwLockMappedWriteGuard<'a, T>
This guard as a RwLockMappedWriteGuard, for a struct field that
holds one. The same as RwLockWriteGuard::map(guard, |me| me).
Sourcepub fn downgrade(self) -> RwLockReadGuard<'a, T>
pub fn downgrade(self) -> RwLockReadGuard<'a, T>
Turns the write into a read in one step, so no writer gets in between.
This does not necessarily let more readers in: a writer may be next in line. The readers queued behind a writer-free front share the lock now, and are woken to do so.
It makes the progress a release does (see RwLockReadGuard).
use nuclei::sync::RwLock;
let lock = RwLock::new(1);
let mut write = lock.try_write().expect("free");
*write += 1;
let read = write.downgrade();
assert_eq!(*read, 2);
assert!(lock.try_write().is_err(), "the read is still held");
assert!(lock.try_read().is_ok(), "readers share it");