Coverage Report

Created: 2024-10-16 07:58

/rust/registry/src/index.crates.io-6f17d22bba15001f/dashmap-6.0.1/src/t.rs
Line
Count
Source (jump to first uncovered line)
1
//! Central map trait to ease modifications and extensions down the road.
2
3
use crate::iter::{Iter, IterMut};
4
use crate::lock::{RwLockReadGuard, RwLockWriteGuard};
5
use crate::mapref::entry::Entry;
6
use crate::mapref::one::{Ref, RefMut};
7
use crate::try_result::TryResult;
8
use crate::HashMap;
9
use core::borrow::Borrow;
10
use core::hash::{BuildHasher, Hash};
11
12
/// Implementation detail that is exposed due to generic constraints in public types.
13
pub trait Map<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + Clone + BuildHasher> {
14
    fn _shard_count(&self) -> usize;
15
16
    /// # Safety
17
    ///
18
    /// The index must not be out of bounds.
19
    unsafe fn _get_read_shard(&'a self, i: usize) -> &'a HashMap<K, V>;
20
21
    /// # Safety
22
    ///
23
    /// The index must not be out of bounds.
24
    unsafe fn _yield_read_shard(&'a self, i: usize) -> RwLockReadGuard<'a, HashMap<K, V>>;
25
26
    /// # Safety
27
    ///
28
    /// The index must not be out of bounds.
29
    unsafe fn _yield_write_shard(&'a self, i: usize) -> RwLockWriteGuard<'a, HashMap<K, V>>;
30
31
    /// # Safety
32
    ///
33
    /// The index must not be out of bounds.
34
    unsafe fn _try_yield_read_shard(
35
        &'a self,
36
        i: usize,
37
    ) -> Option<RwLockReadGuard<'a, HashMap<K, V>>>;
38
39
    /// # Safety
40
    ///
41
    /// The index must not be out of bounds.
42
    unsafe fn _try_yield_write_shard(
43
        &'a self,
44
        i: usize,
45
    ) -> Option<RwLockWriteGuard<'a, HashMap<K, V>>>;
46
47
    fn _insert(&self, key: K, value: V) -> Option<V>;
48
49
    fn _remove<Q>(&self, key: &Q) -> Option<(K, V)>
50
    where
51
        K: Borrow<Q>,
52
        Q: Hash + Eq + ?Sized;
53
54
    fn _remove_if<Q>(&self, key: &Q, f: impl FnOnce(&K, &V) -> bool) -> Option<(K, V)>
55
    where
56
        K: Borrow<Q>,
57
        Q: Hash + Eq + ?Sized;
58
59
    fn _remove_if_mut<Q>(&self, key: &Q, f: impl FnOnce(&K, &mut V) -> bool) -> Option<(K, V)>
60
    where
61
        K: Borrow<Q>,
62
        Q: Hash + Eq + ?Sized;
63
64
    fn _iter(&'a self) -> Iter<'a, K, V, S, Self>
65
    where
66
        Self: Sized;
67
68
    fn _iter_mut(&'a self) -> IterMut<'a, K, V, S, Self>
69
    where
70
        Self: Sized;
71
72
    fn _get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V>>
73
    where
74
        K: Borrow<Q>,
75
        Q: Hash + Eq + ?Sized;
76
77
    fn _get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V>>
78
    where
79
        K: Borrow<Q>,
80
        Q: Hash + Eq + ?Sized;
81
82
    fn _try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V>>
83
    where
84
        K: Borrow<Q>,
85
        Q: Hash + Eq + ?Sized;
86
87
    fn _try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V>>
88
    where
89
        K: Borrow<Q>,
90
        Q: Hash + Eq + ?Sized;
91
92
    fn _shrink_to_fit(&self);
93
94
    fn _retain(&self, f: impl FnMut(&K, &mut V) -> bool);
95
96
    fn _len(&self) -> usize;
97
98
    fn _capacity(&self) -> usize;
99
100
    fn _alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
101
    where
102
        K: Borrow<Q>,
103
        Q: Hash + Eq + ?Sized;
104
105
    fn _alter_all(&self, f: impl FnMut(&K, V) -> V);
106
107
    fn _view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
108
    where
109
        K: Borrow<Q>,
110
        Q: Hash + Eq + ?Sized;
111
112
    fn _entry(&'a self, key: K) -> Entry<'a, K, V>;
113
114
    fn _try_entry(&'a self, key: K) -> Option<Entry<'a, K, V>>;
115
116
    fn _hasher(&self) -> S;
117
118
    // provided
119
0
    fn _clear(&self) {
120
0
        self._retain(|_, _| false)
121
0
    }
122
123
0
    fn _contains_key<Q>(&'a self, key: &Q) -> bool
124
0
    where
125
0
        K: Borrow<Q>,
126
0
        Q: Hash + Eq + ?Sized,
127
0
    {
128
0
        self._get(key).is_some()
129
0
    }
130
131
0
    fn _is_empty(&self) -> bool {
132
0
        self._len() == 0
133
0
    }
134
}