summaryrefslogtreecommitdiff
path: root/melib/src/collection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'melib/src/collection.rs')
-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")
+ }
+}