melib: add As{Ref,Mut} impls for RwRef{,Mut}

pull/168/head
Manos Pitsidianakis 2022-11-07 16:25:37 +02:00
parent 59b95f83d2
commit 56fc43bcf8
1 changed files with 18 additions and 0 deletions

View File

@ -479,6 +479,12 @@ impl<K: std::cmp::Eq + std::hash::Hash, V> Deref for RwRef<'_, K, V> {
}
}
impl<K: std::cmp::Eq + std::hash::Hash, V> AsRef<V> for RwRef<'_, K, V> {
fn as_ref(&self) -> &V {
self.guard.get(&self.hash).expect("Hash was not found")
}
}
pub struct RwRefMut<'g, K: std::cmp::Eq + std::hash::Hash, V> {
guard: RwLockWriteGuard<'g, HashMap<K, V>>,
hash: K,
@ -497,3 +503,15 @@ impl<K: std::cmp::Eq + std::hash::Hash, V> Deref for RwRefMut<'_, K, V> {
self.guard.get(&self.hash).expect("Hash was not found")
}
}
impl<K: std::cmp::Eq + std::hash::Hash, V> AsRef<V> for RwRefMut<'_, K, V> {
fn as_ref(&self) -> &V {
self.guard.get(&self.hash).expect("Hash was not found")
}
}
impl<K: std::cmp::Eq + std::hash::Hash, V> AsMut<V> for RwRefMut<'_, K, V> {
fn as_mut(&mut self) -> &mut V {
self.guard.get_mut(&self.hash).expect("Hash was not found")
}
}