pub struct RwLockWriteGuard<'rwlock, T>where
    T: 'rwlock + ?Sized,{ /* private fields */ }Expand description
Implementations§
Source§impl<'rwlock, T> RwLockWriteGuard<'rwlock, T>where
    T: ?Sized,
 
impl<'rwlock, T> RwLockWriteGuard<'rwlock, T>where
    T: ?Sized,
1.93.0 · Sourcepub fn downgrade(s: RwLockWriteGuard<'rwlock, T>) -> RwLockReadGuard<'rwlock, T>
 
pub fn downgrade(s: RwLockWriteGuard<'rwlock, T>) -> RwLockReadGuard<'rwlock, T>
Downgrades a write-locked RwLockWriteGuard into a read-locked RwLockReadGuard.
Since we have the RwLockWriteGuard, the RwLock must already be locked for writing, so
this method cannot fail.
After downgrading, other readers will be allowed to read the protected data.
§Examples
downgrade takes ownership of the RwLockWriteGuard and returns a RwLockReadGuard.
use std::sync::{RwLock, RwLockWriteGuard};
let rw = RwLock::new(0);
let mut write_guard = rw.write().unwrap();
*write_guard = 42;
let read_guard = RwLockWriteGuard::downgrade(write_guard);
assert_eq!(42, *read_guard);downgrade will atomically change the state of the RwLock from exclusive mode into
shared mode. This means that it is impossible for another writing thread to get in between a
thread calling downgrade and any reads it performs after downgrading.
use std::sync::{Arc, RwLock, RwLockWriteGuard};
let rw = Arc::new(RwLock::new(1));
// Put the lock in write mode.
let mut main_write_guard = rw.write().unwrap();
let rw_clone = rw.clone();
let evil_handle = std::thread::spawn(move || {
    // This will not return until the main thread drops the `main_read_guard`.
    let mut evil_guard = rw_clone.write().unwrap();
    assert_eq!(*evil_guard, 2);
    *evil_guard = 3;
});
*main_write_guard = 2;
// Atomically downgrade the write guard into a read guard.
let main_read_guard = RwLockWriteGuard::downgrade(main_write_guard);
// Since `downgrade` is atomic, the writer thread cannot have changed the protected data.
assert_eq!(*main_read_guard, 2, "`downgrade` was not atomic");Sourcepub fn map<U, F>(
    orig: RwLockWriteGuard<'rwlock, T>,
    f: F,
) -> MappedRwLockWriteGuard<'rwlock, U>
 🔬This is a nightly-only experimental API. (mapped_lock_guards)
pub fn map<U, F>( orig: RwLockWriteGuard<'rwlock, T>, f: F, ) -> MappedRwLockWriteGuard<'rwlock, U>
mapped_lock_guards)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
RwLockWriteGuard::map(...). A method would interfere with methods of
the same name on the contents of the RwLockWriteGuard used through
Deref.
§Panics
If the closure panics, the guard will be dropped (unlocked) and the RwLock will be poisoned.
Sourcepub fn filter_map<U, F>(
    orig: RwLockWriteGuard<'rwlock, T>,
    f: F,
) -> Result<MappedRwLockWriteGuard<'rwlock, U>, RwLockWriteGuard<'rwlock, T>>
 🔬This is a nightly-only experimental API. (mapped_lock_guards)
pub fn filter_map<U, F>( orig: RwLockWriteGuard<'rwlock, T>, f: F, ) -> Result<MappedRwLockWriteGuard<'rwlock, U>, RwLockWriteGuard<'rwlock, T>>
mapped_lock_guards)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
RwLockWriteGuard::filter_map(...). A method would interfere with methods
of the same name on the contents of the RwLockWriteGuard used through
Deref.
§Panics
If the closure panics, the guard will be dropped (unlocked) and the RwLock will be poisoned.
Trait Implementations§
1.16.0 · Source§impl<T> Debug for RwLockWriteGuard<'_, T>
 
impl<T> Debug for RwLockWriteGuard<'_, T>
1.0.0 · Source§impl<T> Deref for RwLockWriteGuard<'_, T>where
    T: ?Sized,
 
impl<T> Deref for RwLockWriteGuard<'_, T>where
    T: ?Sized,
1.0.0 · Source§impl<T> DerefMut for RwLockWriteGuard<'_, T>where
    T: ?Sized,
 
impl<T> DerefMut for RwLockWriteGuard<'_, T>where
    T: ?Sized,
1.20.0 · Source§impl<T> Display for RwLockWriteGuard<'_, T>
 
impl<T> Display for RwLockWriteGuard<'_, T>
1.0.0 · Source§impl<T> Drop for RwLockWriteGuard<'_, T>where
    T: ?Sized,
 
impl<T> Drop for RwLockWriteGuard<'_, T>where
    T: ?Sized,
impl<T> !Send for RwLockWriteGuard<'_, T>where
    T: ?Sized,
impl<T> Sync for RwLockWriteGuard<'_, T>
Auto Trait Implementations§
impl<'rwlock, T> Freeze for RwLockWriteGuard<'rwlock, T>where
    T: ?Sized,
impl<'rwlock, T> RefUnwindSafe for RwLockWriteGuard<'rwlock, T>where
    T: ?Sized,
impl<'rwlock, T> Unpin for RwLockWriteGuard<'rwlock, T>where
    T: ?Sized,
impl<'rwlock, T> UnwindSafe for RwLockWriteGuard<'rwlock, T>where
    T: ?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<R> Rng for R
 
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
 
fn random<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
 
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
 
fn random_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
 
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
 
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
    D: Distribution<T>,
 
fn sample<T, D>(&mut self, distr: D) -> Twhere
    D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
    D: Distribution<T>,
    Self: Sized,
 
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
    D: Distribution<T>,
    Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
 
fn gen<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
random to avoid conflict with the new gen keyword in Rust 2024.Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
 
fn gen_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
random_rangeRng::random_range.Source§impl<R> TryRngCore for R
 
impl<R> TryRngCore for R
Source§type Error = Infallible
 
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
 
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
 
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
    &mut self,
    dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
 
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
 
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
    Self: Sized,
 
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
    Self: Sized,
RngCore to a RngReadAdapter.