Skip to content

Commit f64ea40

Browse files
authored
Add support for hashbrown v0.16 (#888)
2 parents d34d9c4 + b4c58d4 commit f64ea40

File tree

17 files changed

+537
-1
lines changed

17 files changed

+537
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
- name: "Check no_std+alloc (No Default Features / ${{ matrix.os }} / ${{ matrix.rust }})"
9090
run: cargo check --package serde_with --no-default-features --features=alloc --target thumbv7em-none-eabihf
9191
- name: "Check no_std+alloc+optional (No Default Features / ${{ matrix.os }} / ${{ matrix.rust }})"
92-
run: cargo check --package serde_with --no-default-features --features=alloc,base64,chrono_0_4,hashbrown_0_14,hashbrown_0_15,hex,indexmap_1,indexmap_2,json,time_0_3 --target thumbv7em-none-eabihf
92+
run: cargo check --package serde_with --no-default-features --features=alloc,base64,chrono_0_4,hashbrown_0_14,hashbrown_0_15,hashbrown_0_16,hex,indexmap_1,indexmap_2,json,time_0_3 --target thumbv7em-none-eabihf
9393

9494
# The tests are split into build and run steps, to see the time impact of each
9595
# cargo test --all-targets does NOT run doctests

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

serde_with/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2828
);
2929
```
3030

31+
* Add support for `hashbrown` v0.16 (#877)
32+
33+
This extends the existing support for `hashbrown` v0.14 and v0.15 to the newly released version.
34+
3135
## [3.14.1] - 2025-09-19
3236

3337
### Fixed

serde_with/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ hashbrown_0_14 = ["dep:hashbrown_0_14", "alloc"]
8181
## It enables the `alloc` feature.
8282
## Some functionality is only available when `std` is enabled too.
8383
hashbrown_0_15 = ["dep:hashbrown_0_15", "alloc"]
84+
## The feature enables `hashbrown::{HashMap, HashSet}` as supported containers.
85+
##
86+
## This pulls in [`hashbrown` v0.16](::hashbrown_0_16) as a dependency.
87+
## It enables the `alloc` feature.
88+
## Some functionality is only available when `std` is enabled too.
89+
hashbrown_0_16 = ["dep:hashbrown_0_16", "alloc"]
8490
## The feature enables serializing data in hex format.
8591
##
8692
## This pulls in [`hex`] as a dependency.
@@ -148,6 +154,7 @@ chrono_0_4 = { package = "chrono", version = "0.4.20", optional = true, default-
148154
document-features = { version = "0.2.7", optional = true }
149155
hashbrown_0_14 = { package = "hashbrown", version = "0.14.0", optional = true, default-features = false, features = ["serde"] }
150156
hashbrown_0_15 = { package = "hashbrown", version = "0.15.0", optional = true, default-features = false, features = ["serde"] }
157+
hashbrown_0_16 = { package = "hashbrown", version = "0.16.0", optional = true, default-features = false, features = ["serde"] }
151158
hex = { version = "0.4.3", optional = true, default-features = false }
152159
indexmap_1 = { package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"] }
153160
indexmap_2 = { package = "indexmap", version = "2.0", optional = true, default-features = false, features = ["serde"] }
@@ -206,6 +213,11 @@ name = "hashbrown_0_15"
206213
path = "tests/hashbrown_0_15.rs"
207214
required-features = ["hashbrown_0_15", "macros"]
208215

216+
[[test]]
217+
name = "hashbrown_0_16"
218+
path = "tests/hashbrown_0_16.rs"
219+
required-features = ["hashbrown_0_16", "macros"]
220+
209221
[[test]]
210222
name = "indexmap_1"
211223
path = "tests/indexmap_1.rs"

serde_with/src/de/duplicates.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::{
1010
use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014};
1111
#[cfg(feature = "hashbrown_0_15")]
1212
use hashbrown_0_15::{HashMap as HashbrownMap015, HashSet as HashbrownSet015};
13+
#[cfg(feature = "hashbrown_0_16")]
14+
use hashbrown_0_16::{HashMap as HashbrownMap016, HashSet as HashbrownSet016};
1315
#[cfg(feature = "indexmap_1")]
1416
use indexmap_1::{IndexMap, IndexSet};
1517
#[cfg(feature = "indexmap_2")]

serde_with/src/de/impls.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::{formats::*, prelude::*};
44
use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014};
55
#[cfg(feature = "hashbrown_0_15")]
66
use hashbrown_0_15::{HashMap as HashbrownMap015, HashSet as HashbrownSet015};
7+
#[cfg(feature = "hashbrown_0_16")]
8+
use hashbrown_0_16::{HashMap as HashbrownMap016, HashSet as HashbrownSet016};
79
#[cfg(feature = "indexmap_1")]
810
use indexmap_1::{IndexMap, IndexSet};
911
#[cfg(feature = "indexmap_2")]
@@ -39,6 +41,11 @@ pub(crate) mod macros {
3941
HashbrownMap015<K: Eq + Hash, V, S: BuildHasher + Default>,
4042
(|size| HashbrownMap015::with_capacity_and_hasher(size, Default::default()))
4143
);
44+
#[cfg(feature = "hashbrown_0_16")]
45+
$m!(
46+
HashbrownMap016<K: Eq + Hash, V, S: BuildHasher + Default>,
47+
(|size| HashbrownMap016::with_capacity_and_hasher(size, Default::default()))
48+
);
4249
#[cfg(feature = "indexmap_1")]
4350
$m!(
4451
IndexMap<K: Eq + Hash, V, S: BuildHasher + Default>,
@@ -74,6 +81,12 @@ pub(crate) mod macros {
7481
(|size| HashbrownSet015::with_capacity_and_hasher(size, S::default())),
7582
insert
7683
);
84+
#[cfg(feature = "hashbrown_0_16")]
85+
$m!(
86+
HashbrownSet016<T: Eq + Hash, S: BuildHasher + Default>,
87+
(|size| HashbrownSet016::with_capacity_and_hasher(size, S::default())),
88+
insert
89+
);
7790
#[cfg(feature = "indexmap_1")]
7891
$m!(
7992
IndexSet<T: Eq + Hash, S: BuildHasher + Default>,

serde_with/src/de/skip_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::prelude::*;
44
use hashbrown_0_14::HashMap as HashbrownMap014;
55
#[cfg(feature = "hashbrown_0_15")]
66
use hashbrown_0_15::HashMap as HashbrownMap015;
7+
#[cfg(feature = "hashbrown_0_16")]
8+
use hashbrown_0_16::HashMap as HashbrownMap016;
79
#[cfg(feature = "indexmap_1")]
810
use indexmap_1::IndexMap;
911
#[cfg(feature = "indexmap_2")]

serde_with/src/duplicate_key_impls/error_on_duplicate.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ where
7474
}
7575
}
7676

77+
#[cfg(feature = "hashbrown_0_16")]
78+
impl<T, S> PreventDuplicateInsertsSet<T> for hashbrown_0_16::HashSet<T, S>
79+
where
80+
T: Eq + Hash,
81+
S: BuildHasher + Default,
82+
{
83+
#[inline]
84+
fn new(size_hint: Option<usize>) -> Self {
85+
match size_hint {
86+
Some(size) => Self::with_capacity_and_hasher(size, S::default()),
87+
None => Self::with_hasher(S::default()),
88+
}
89+
}
90+
91+
#[inline]
92+
fn insert(&mut self, value: T) -> bool {
93+
self.insert(value)
94+
}
95+
}
96+
7797
#[cfg(feature = "indexmap_1")]
7898
impl<T, S> PreventDuplicateInsertsSet<T> for indexmap_1::IndexSet<T, S>
7999
where
@@ -189,6 +209,26 @@ where
189209
}
190210
}
191211

212+
#[cfg(feature = "hashbrown_0_16")]
213+
impl<K, V, S> PreventDuplicateInsertsMap<K, V> for hashbrown_0_16::HashMap<K, V, S>
214+
where
215+
K: Eq + Hash,
216+
S: BuildHasher + Default,
217+
{
218+
#[inline]
219+
fn new(size_hint: Option<usize>) -> Self {
220+
match size_hint {
221+
Some(size) => Self::with_capacity_and_hasher(size, S::default()),
222+
None => Self::with_hasher(S::default()),
223+
}
224+
}
225+
226+
#[inline]
227+
fn insert(&mut self, key: K, value: V) -> bool {
228+
self.insert(key, value).is_none()
229+
}
230+
}
231+
192232
#[cfg(feature = "indexmap_1")]
193233
impl<K, V, S> PreventDuplicateInsertsMap<K, V> for indexmap_1::IndexMap<K, V, S>
194234
where

serde_with/src/duplicate_key_impls/first_value_wins.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,34 @@ where
9191
}
9292
}
9393

94+
#[cfg(feature = "hashbrown_0_16")]
95+
impl<K, V, S> DuplicateInsertsFirstWinsMap<K, V> for hashbrown_0_16::HashMap<K, V, S>
96+
where
97+
K: Eq + Hash,
98+
S: BuildHasher + Default,
99+
{
100+
#[inline]
101+
fn new(size_hint: Option<usize>) -> Self {
102+
match size_hint {
103+
Some(size) => Self::with_capacity_and_hasher(size, S::default()),
104+
None => Self::with_hasher(S::default()),
105+
}
106+
}
107+
108+
#[inline]
109+
fn insert(&mut self, key: K, value: V) {
110+
use hashbrown_0_16::hash_map::Entry;
111+
112+
match self.entry(key) {
113+
// we want to keep the first value, so do nothing
114+
Entry::Occupied(_) => {}
115+
Entry::Vacant(vacant) => {
116+
vacant.insert(value);
117+
}
118+
}
119+
}
120+
}
121+
94122
#[cfg(feature = "indexmap_1")]
95123
impl<K, V, S> DuplicateInsertsFirstWinsMap<K, V> for indexmap_1::IndexMap<K, V, S>
96124
where

serde_with/src/duplicate_key_impls/last_value_wins.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ where
7070
}
7171
}
7272

73+
#[cfg(feature = "hashbrown_0_16")]
74+
impl<T, S> DuplicateInsertsLastWinsSet<T> for hashbrown_0_16::HashSet<T, S>
75+
where
76+
T: Eq + Hash,
77+
S: BuildHasher + Default,
78+
{
79+
#[inline]
80+
fn new(size_hint: Option<usize>) -> Self {
81+
match size_hint {
82+
Some(size) => Self::with_capacity_and_hasher(size, S::default()),
83+
None => Self::with_hasher(S::default()),
84+
}
85+
}
86+
87+
#[inline]
88+
fn replace(&mut self, value: T) {
89+
// Hashset already fulfils the contract
90+
self.replace(value);
91+
}
92+
}
93+
7394
#[cfg(feature = "indexmap_1")]
7495
impl<T, S> DuplicateInsertsLastWinsSet<T> for indexmap_1::IndexSet<T, S>
7596
where

0 commit comments

Comments
 (0)