use std::sync::{Mutex as StdMutex, RwLock as StdRwLock};
pub use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};
#[derive(Debug, Default)]
pub struct RwLock<T: ?Sized>(StdRwLock<T>);
impl<T> RwLock<T> {
pub fn new(t: T) -> Self {
RwLock(StdRwLock::new(t))
}
}
impl<T: ?Sized> RwLock<T> {
pub fn read(&self) -> RwLockReadGuard<'_, T> {
self.0.read().expect("acquiring a poisoned rwlock")
}
pub fn write(&self) -> RwLockWriteGuard<'_, T> {
self.0.write().expect("acquiring a poisoned rwlock")
}
}
#[derive(Debug, Default)]
pub struct Mutex<T: ?Sized>(StdMutex<T>);
impl<T> Mutex<T> {
pub fn new(t: T) -> Self {
Mutex(StdMutex::new(t))
}
pub fn into_inner(self) -> T {
self.0.into_inner().expect("acquiring a poisoned mutex")
}
}
impl<T: ?Sized> Mutex<T> {
pub fn lock(&self) -> MutexGuard<'_, T> {
self.0.lock().expect("acquiring a poisoned mutex")
}
}