Switch out .X().unwrap() for .unwrapped_X

This commit is contained in:
Gav Wood
2016-07-07 09:37:31 +02:00
parent 456ad9e21b
commit 3b662c285f
31 changed files with 335 additions and 311 deletions

View File

@@ -75,3 +75,18 @@ pub trait Lockable<T> {
impl<T: Sized> Lockable<T> for Mutex<T> {
fn locked(&self) -> MutexGuard<T> { self.lock().unwrap() }
}
/// Object can be read or write locked directly into a guard.
pub trait RwLockable<T> {
/// Read-lock object directly into a `ReadGuard`.
fn unwrapped_read(&self) -> RwLockReadGuard<T>;
/// Write-lock object directly into a `WriteGuard`.
fn unwrapped_write(&self) -> RwLockWriteGuard<T>;
}
impl<T: Sized> RwLockable<T> for RwLock<T> {
fn unwrapped_read(&self) -> RwLockReadGuard<T> { self.read().unwrap() }
fn unwrapped_write(&self) -> RwLockWriteGuard<T> { self.write().unwrap() }
}