summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2022-11-07 16:25:37 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2022-11-07 16:25:37 +0200
commit56fc43bcf869a867455b44d007b9d3d17422bc8d (patch)
tree9bbe7974869e6f8e6c22a8eff8f520ee55c5c5aa
parent59b95f83d2b388b30a3a855f68bf5952355597d7 (diff)
downloadmeli-56fc43bcf869a867455b44d007b9d3d17422bc8d.zip
melib: add As{Ref,Mut} impls for RwRef{,Mut}
-rw-r--r--melib/src/collection.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/melib/src/collection.rs b/melib/src/collection.rs
index f686dcec..82df499d 100644
--- a/melib/src/collection.rs
+++ b/melib/src/collection.rs
@@ -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")
+ }
+}