pub trait RwLockExt<T> {
    // Required methods
    fn force_read(&self) -> RwLockReadGuard<'_, T>;
    fn force_write(&self) -> RwLockWriteGuard<'_, T>;
}
Expand description

Extension trait with useful methods for std::sync::RwLock.

Required Methods§

source

fn force_read(&self) -> RwLockReadGuard<'_, T>

Shorthand for lock.read().unwrap() with a better panic message.

This method is intended to be used in situations where poisoned locks are considered an exceptional situation and should always result in panic.

§Examples
use std::sync::{Arc, RwLock};
use stdext::prelude::*;

let lock = Arc::new(RwLock::new(1));

let n = lock.force_read();
assert_eq!(*n, 1);
source

fn force_write(&self) -> RwLockWriteGuard<'_, T>

Shorthand for lock.write().unwrap() with a better panic message.

This method is intended to be used in situations where poisoned locks are considered an exceptional situation and should always result in panic.

§Examples
use std::sync::{Arc, RwLock};
use stdext::prelude::*;

let lock = Arc::new(RwLock::new(1));

{
    let mut n = lock.force_write();
    *n = 2;
}

let n = lock.force_read();
assert_eq!(*n, 2);

Implementations on Foreign Types§

source§

impl<T> RwLockExt<T> for RwLock<T>

Implementors§