/rust/registry/src/index.crates.io-1949cf8c6b5b557f/dashmap-6.1.0/src/mapref/multiple.rs
Line | Count | Source |
1 | | use crate::lock::{RwLockReadGuard, RwLockWriteGuard}; |
2 | | use crate::HashMap; |
3 | | use core::hash::Hash; |
4 | | use core::ops::{Deref, DerefMut}; |
5 | | use std::sync::Arc; |
6 | | |
7 | | pub struct RefMulti<'a, K, V> { |
8 | | _guard: Arc<RwLockReadGuard<'a, HashMap<K, V>>>, |
9 | | k: *const K, |
10 | | v: *const V, |
11 | | } |
12 | | |
13 | | unsafe impl<'a, K: Eq + Hash + Sync, V: Sync> Send for RefMulti<'a, K, V> {} |
14 | | unsafe impl<'a, K: Eq + Hash + Sync, V: Sync> Sync for RefMulti<'a, K, V> {} |
15 | | |
16 | | impl<'a, K: Eq + Hash, V> RefMulti<'a, K, V> { |
17 | 0 | pub(crate) unsafe fn new( |
18 | 0 | guard: Arc<RwLockReadGuard<'a, HashMap<K, V>>>, |
19 | 0 | k: *const K, |
20 | 0 | v: *const V, |
21 | 0 | ) -> Self { |
22 | 0 | Self { |
23 | 0 | _guard: guard, |
24 | 0 | k, |
25 | 0 | v, |
26 | 0 | } |
27 | 0 | } |
28 | | |
29 | 0 | pub fn key(&self) -> &K { |
30 | 0 | self.pair().0 |
31 | 0 | } |
32 | | |
33 | 0 | pub fn value(&self) -> &V { |
34 | 0 | self.pair().1 |
35 | 0 | } |
36 | | |
37 | 0 | pub fn pair(&self) -> (&K, &V) { |
38 | 0 | unsafe { (&*self.k, &*self.v) } |
39 | 0 | } |
40 | | } |
41 | | |
42 | | impl<'a, K: Eq + Hash, V> Deref for RefMulti<'a, K, V> { |
43 | | type Target = V; |
44 | | |
45 | 0 | fn deref(&self) -> &V { |
46 | 0 | self.value() |
47 | 0 | } |
48 | | } |
49 | | |
50 | | pub struct RefMutMulti<'a, K, V> { |
51 | | _guard: Arc<RwLockWriteGuard<'a, HashMap<K, V>>>, |
52 | | k: *const K, |
53 | | v: *mut V, |
54 | | } |
55 | | |
56 | | unsafe impl<'a, K: Eq + Hash + Sync, V: Sync> Send for RefMutMulti<'a, K, V> {} |
57 | | unsafe impl<'a, K: Eq + Hash + Sync, V: Sync> Sync for RefMutMulti<'a, K, V> {} |
58 | | |
59 | | impl<'a, K: Eq + Hash, V> RefMutMulti<'a, K, V> { |
60 | 0 | pub(crate) unsafe fn new( |
61 | 0 | guard: Arc<RwLockWriteGuard<'a, HashMap<K, V>>>, |
62 | 0 | k: *const K, |
63 | 0 | v: *mut V, |
64 | 0 | ) -> Self { |
65 | 0 | Self { |
66 | 0 | _guard: guard, |
67 | 0 | k, |
68 | 0 | v, |
69 | 0 | } |
70 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>>>::new Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _>>::new |
71 | | |
72 | 0 | pub fn key(&self) -> &K { |
73 | 0 | self.pair().0 |
74 | 0 | } |
75 | | |
76 | 0 | pub fn value(&self) -> &V { |
77 | 0 | self.pair().1 |
78 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>>>::value Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _>>::value |
79 | | |
80 | 0 | pub fn value_mut(&mut self) -> &mut V { |
81 | 0 | self.pair_mut().1 |
82 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>>>::value_mut Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _>>::value_mut |
83 | | |
84 | 0 | pub fn pair(&self) -> (&K, &V) { |
85 | 0 | unsafe { (&*self.k, &*self.v) } |
86 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>>>::pair Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _>>::pair |
87 | | |
88 | 0 | pub fn pair_mut(&mut self) -> (&K, &mut V) { |
89 | 0 | unsafe { (&*self.k, &mut *self.v) } |
90 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>>>::pair_mut Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _>>::pair_mut |
91 | | } |
92 | | |
93 | | impl<'a, K: Eq + Hash, V> Deref for RefMutMulti<'a, K, V> { |
94 | | type Target = V; |
95 | | |
96 | 0 | fn deref(&self) -> &V { |
97 | 0 | self.value() |
98 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>> as core::ops::deref::Deref>::deref Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _> as core::ops::deref::Deref>::deref |
99 | | } |
100 | | |
101 | | impl<'a, K: Eq + Hash, V> DerefMut for RefMutMulti<'a, K, V> { |
102 | 0 | fn deref_mut(&mut self) -> &mut V { |
103 | 0 | self.value_mut() |
104 | 0 | } Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<usize, core::option::Option<gix_tempfile::forksafe::ForksafeTempfile>> as core::ops::deref::DerefMut>::deref_mut Unexecuted instantiation: <dashmap::mapref::multiple::RefMutMulti<_, _> as core::ops::deref::DerefMut>::deref_mut |
105 | | } |