1use crate::common::concurrent::ValueEntry;
2
3use std::{
4 hash::{BuildHasher, Hash},
5 sync::Arc,
6};
7use triomphe::Arc as TrioArc;
8
9type DashMapRef<'a, K, V, S> =
10 dashmap::mapref::multiple::RefMulti<'a, Arc<K>, TrioArc<ValueEntry<K, V>>, S>;
11
12pub struct EntryRef<'a, K, V, S>(DashMapRef<'a, K, V, S>);
13
14unsafe impl<'a, K, V, S> Sync for EntryRef<'a, K, V, S>
15where
16 K: Eq + Hash + Send + Sync,
17 V: Send + Sync,
18 S: BuildHasher,
19{
20}
21
22impl<'a, K, V, S> EntryRef<'a, K, V, S>
23where
24 K: Eq + Hash,
25 S: BuildHasher + Clone,
26{
27 pub(crate) fn new(map_ref: DashMapRef<'a, K, V, S>) -> Self {
28 Self(map_ref)
29 }
30
31 pub fn key(&self) -> &K {
32 self.0.key()
33 }
34
35 pub fn value(&self) -> &V {
36 &self.0.value().value
37 }
38
39 pub fn pair(&self) -> (&K, &V) {
40 (self.key(), self.value())
41 }
42}
43
44impl<'a, K, V, S> std::ops::Deref for EntryRef<'a, K, V, S>
45where
46 K: Eq + Hash,
47 S: BuildHasher + Clone,
48{
49 type Target = V;
50
51 fn deref(&self) -> &V {
52 self.value()
53 }
54}