use crate::shard::{ShardReader, ShardWriter};
pub struct MapRef<'a, K, V> {
key: &'a K,
value: &'a V,
#[allow(unused)]
reader: ShardReader<'a, K, V>,
}
impl<K, V> std::ops::Deref for MapRef<'_, K, V>
where
K: Eq + std::hash::Hash,
{
type Target = V;
fn deref(&self) -> &Self::Target {
self.value
}
}
impl<'a, K, V> MapRef<'a, K, V>
where
K: Eq + std::hash::Hash,
{
pub(crate) fn new(reader: ShardReader<'a, K, V>, key: &'a K, value: &'a V) -> Self {
Self { reader, key, value }
}
pub fn key(&self) -> &K {
self.key
}
pub fn value(&self) -> &V {
self.value
}
pub fn pair(&self) -> (&K, &V) {
(self.key, self.value)
}
}
pub struct MapRefMut<'a, K, V> {
key: &'a K,
value: &'a mut V,
#[allow(unused)]
writer: ShardWriter<'a, K, V>,
}
impl<'a, K, V> std::ops::Deref for MapRefMut<'a, K, V>
where
K: Eq + std::hash::Hash,
{
type Target = V;
fn deref(&self) -> &Self::Target {
self.value
}
}
impl<'a, K, V> std::ops::DerefMut for MapRefMut<'a, K, V>
where
K: Eq + std::hash::Hash,
{
fn deref_mut(&mut self) -> &mut Self::Target {
self.value
}
}
impl<'a, K, V> MapRefMut<'a, K, V>
where
K: Eq + std::hash::Hash,
{
pub(crate) fn new(writer: ShardWriter<'a, K, V>, key: &'a K, value: &'a mut V) -> Self {
Self { writer, key, value }
}
pub fn key(&self) -> &K {
self.key
}
pub fn value(&self) -> &V {
self.value
}
pub fn value_mut(&mut self) -> &mut V {
self.value
}
pub fn pair(&self) -> (&K, &V) {
(self.key, self.value)
}
pub fn pair_mut(&mut self) -> (&K, &mut V) {
(self.key, self.value)
}
}