use super::*;
use std::collections::hash_map::Entry;
macro_rules! readable {
() => {
pub fn get(&self) -> Option<&V> {
self.map.get(&self.key)
}
pub fn get_key_value(&self) -> Option<(&K, &V)> {
self.map.get_key_value(&self.key)
}
pub fn contains_key(&self) -> bool {
self.map.contains_key(&self.key)
}
};
}
#[derive(Debug)]
pub struct Readable<'a, K, V, S> {
pub(super) key: &'a K,
pub(super) map: RwLockReadGuard<'a, Map<K, V, S>>,
}
impl<K: Eq + Hash, V, S: BuildHasher> Readable<'_, K, V, S> {
readable!();
}
#[derive(Debug)]
pub struct Writeable<'a, K, V, S> {
pub(super) key: K,
pub(super) map: RwLockWriteGuard<'a, Map<K, V, S>>,
}
impl<K: Eq + Hash, V, S: BuildHasher> Writeable<'_, K, V, S> {
readable!();
pub fn get_mut(&mut self) -> Option<&mut V> {
self.map.get_mut(&self.key)
}
pub fn insert(mut self, value: V) -> Option<V> {
self.map.insert(self.key, value)
}
pub fn remove(&mut self) -> Option<V> {
self.map.remove(&self.key)
}
pub fn entry(&mut self) -> Entry<'_, K, V>
where
K: Clone,
{
self.map.entry(self.key.clone())
}
pub fn remove_entry(&mut self) -> Option<(K, V)> {
self.map.remove_entry(&self.key)
}
}