use std::sync::*;
pub trait EasyAccessMutex<T> {
fn get(&self) -> MutexGuard<T>;
fn with<F, R>(&self, f: F) -> R
where
F: FnOnce(&mut T) -> R;
}
impl<T> EasyAccessMutex<T> for Mutex<T> {
fn get(&self) -> MutexGuard<T> {
self.lock().expect("Mutex is poisoned")
}
fn with<F, R>(&self, f: F) -> R
where
F: FnOnce(&mut T) -> R,
{
let mut guard = self.lock().expect("Mutex is poisoned");
f(&mut *guard)
}
}