Skip to content

Commit fa7de5d

Browse files
authored
Update to DashMap 6 (#2961)
1 parent ce05277 commit fa7de5d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ bytes = { version = "1.5.0", optional = true }
4949
percent-encoding = { version = "2.3.0", optional = true }
5050
mini-moka = { version = "0.10.2", optional = true }
5151
mime_guess = { version = "2.0.4", optional = true }
52-
dashmap = { version = "5.5.3", features = ["serde"], optional = true }
52+
dashmap = { version = "6.1.0", features = ["serde"], optional = true }
5353
parking_lot = { version = "0.12.1"}
5454
ed25519-dalek = { version = "2.0.0", optional = true }
55-
typesize = { version = "0.1.6", optional = true, features = ["url", "time", "serde_json", "secrecy", "dashmap", "parking_lot", "nonmax", "extract_map_01", "details"] }
55+
typesize = { version = "0.1.6", optional = true, features = ["url", "time", "serde_json", "secrecy", "parking_lot", "nonmax", "extract_map_01"] }
5656
# serde feature only allows for serialisation,
5757
# Serenity workspace crates
5858
serenity-voice-model = { version = "0.2.0", path = "./voice-model", optional = true }
@@ -115,7 +115,7 @@ full = ["default", "collector", "voice", "voice_model", "interactions_endpoint"]
115115
# Enables temporary caching in functions that retrieve data via the HTTP API.
116116
temp_cache = ["cache", "mini-moka", "typesize?/mini_moka"]
117117

118-
typesize = ["dep:typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize"]
118+
typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize"]
119119

120120
# Enables compile-time heavy instrument macros from tracing
121121
tracing_instrument = ["tracing/attributes"]

src/cache/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ struct NotSend;
5656
enum CacheRefInner<'a, K, V, T> {
5757
#[cfg(feature = "temp_cache")]
5858
Arc(Arc<V>),
59-
DashRef(Ref<'a, K, V, BuildHasher>),
60-
DashMappedRef(MappedRef<'a, K, T, V, BuildHasher>),
59+
DashRef(Ref<'a, K, V>),
60+
DashMappedRef(MappedRef<'a, K, T, V>),
6161
ReadGuard(parking_lot::RwLockReadGuard<'a, V>),
6262
}
6363

@@ -79,11 +79,11 @@ impl<'a, K, V, T> CacheRef<'a, K, V, T> {
7979
Self::new(CacheRefInner::Arc(inner.get_inner()))
8080
}
8181

82-
fn from_ref(inner: Ref<'a, K, V, BuildHasher>) -> Self {
82+
fn from_ref(inner: Ref<'a, K, V>) -> Self {
8383
Self::new(CacheRefInner::DashRef(inner))
8484
}
8585

86-
fn from_mapped_ref(inner: MappedRef<'a, K, T, V, BuildHasher>) -> Self {
86+
fn from_mapped_ref(inner: MappedRef<'a, K, T, V>) -> Self {
8787
Self::new(CacheRefInner::DashMappedRef(inner))
8888
}
8989

src/cache/wrappers.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use typesize::TypeSize;
1414
/// A wrapper around Option<DashMap<K, V>> to ease disabling specific cache fields.
1515
pub(crate) struct MaybeMap<K: Eq + Hash, V>(pub(super) Option<DashMap<K, V, BuildHasher>>);
1616
impl<K: Eq + Hash, V> MaybeMap<K, V> {
17-
pub fn iter(&self) -> impl Iterator<Item = RefMulti<'_, K, V, BuildHasher>> {
17+
pub fn iter(&self) -> impl Iterator<Item = RefMulti<'_, K, V>> {
1818
Option::iter(&self.0).flat_map(DashMap::iter)
1919
}
2020

21-
pub fn get(&self, k: &K) -> Option<Ref<'_, K, V, BuildHasher>> {
21+
pub fn get(&self, k: &K) -> Option<Ref<'_, K, V>> {
2222
self.0.as_ref()?.get(k)
2323
}
2424

25-
pub fn get_mut(&self, k: &K) -> Option<RefMut<'_, K, V, BuildHasher>> {
25+
pub fn get_mut(&self, k: &K) -> Option<RefMut<'_, K, V>> {
2626
self.0.as_ref()?.get_mut(k)
2727
}
2828

@@ -59,8 +59,10 @@ impl<K: Eq + Hash + TypeSize, V: TypeSize> TypeSize for MaybeMap<K, V> {
5959
self.0.as_ref().map(DashMap::extra_size).unwrap_or_default()
6060
}
6161

62-
fn get_collection_item_count(&self) -> Option<usize> {
63-
self.0.as_ref().and_then(DashMap::get_collection_item_count)
62+
typesize::if_typesize_details! {
63+
fn get_collection_item_count(&self) -> Option<usize> {
64+
self.0.as_ref().and_then(DashMap::get_collection_item_count)
65+
}
6466
}
6567
}
6668

@@ -69,11 +71,11 @@ impl<K: Eq + Hash + TypeSize, V: TypeSize> TypeSize for MaybeMap<K, V> {
6971
/// map without allowing mutation of internal cache fields, which could cause issues.
7072
pub struct ReadOnlyMapRef<'a, K: Eq + Hash, V>(Option<&'a DashMap<K, V, BuildHasher>>);
7173
impl<'a, K: Eq + Hash, V> ReadOnlyMapRef<'a, K, V> {
72-
pub fn iter(&self) -> impl Iterator<Item = RefMulti<'_, K, V, BuildHasher>> {
74+
pub fn iter(&self) -> impl Iterator<Item = RefMulti<'_, K, V>> {
7375
self.0.into_iter().flat_map(DashMap::iter)
7476
}
7577

76-
pub fn get(&self, k: &K) -> Option<Ref<'_, K, V, BuildHasher>> {
78+
pub fn get(&self, k: &K) -> Option<Ref<'_, K, V>> {
7779
self.0?.get(k)
7880
}
7981

@@ -91,6 +93,10 @@ impl std::hash::Hasher for Hasher {
9193
self.0.write(bytes);
9294
}
9395
}
96+
97+
#[cfg(feature = "typesize")]
98+
impl typesize::TypeSize for Hasher {}
99+
94100
#[derive(Clone, Default)]
95101
pub struct BuildHasher(fxhash::FxBuildHasher);
96102
impl std::hash::BuildHasher for BuildHasher {
@@ -101,6 +107,9 @@ impl std::hash::BuildHasher for BuildHasher {
101107
}
102108
}
103109

110+
#[cfg(feature = "typesize")]
111+
impl typesize::TypeSize for BuildHasher {}
112+
104113
/// Wrapper around `SizableArc<T, Owned>`` with support for disabling typesize.
105114
///
106115
/// This denotes an Arc where T's size should be considered when calling `TypeSize::get_size`

0 commit comments

Comments
 (0)