From c0af576613204eceb738610b02b5c0cb06eae0af Mon Sep 17 00:00:00 2001 From: OliverNChalk <11343499+OliverNChalk@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:51:24 -0500 Subject: [PATCH] address PR feedback --- .github/workflows/ci.yaml | 2 +- Cargo.lock | 7 ----- serde_with/Cargo.toml | 9 +++--- serde_with/src/de/duplicates.rs | 4 +-- serde_with/src/de/impls.rs | 24 +++++++------- .../duplicate_key_impls/error_on_duplicate.rs | 8 ++--- .../duplicate_key_impls/first_value_wins.rs | 6 ++-- .../duplicate_key_impls/last_value_wins.rs | 4 +-- serde_with/src/guide/feature_flags.md | 31 +++++++++---------- serde_with/src/ser/duplicates.rs | 4 +-- serde_with/src/ser/impls.rs | 12 +++---- .../tests/{hashbrown.rs => hashbrown_0_14.rs} | 2 +- 12 files changed, 53 insertions(+), 60 deletions(-) rename serde_with/tests/{hashbrown.rs => hashbrown_0_14.rs} (99%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c28559e7..1fc86609 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -89,7 +89,7 @@ jobs: - name: "Check no_std+alloc (No Default Features / ${{ matrix.os }} / ${{ matrix.rust }})" run: cargo check --package serde_with --no-default-features --features=alloc --target thumbv7em-none-eabihf - name: "Check no_std+alloc+optional (No Default Features / ${{ matrix.os }} / ${{ matrix.rust }})" - run: cargo check --package serde_with --no-default-features --features=alloc,base64,chrono_0_4,hex,indexmap_1,indexmap_2,json,time_0_3 --target thumbv7em-none-eabihf + run: cargo check --package serde_with --no-default-features --features=alloc,base64,chrono_0_4,hashbrown_0_14,hex,indexmap_1,indexmap_2,json,time_0_3 --target thumbv7em-none-eabihf # The tests are split into build and run steps, to see the time impact of each # cargo test --all-targets does NOT run doctests diff --git a/Cargo.lock b/Cargo.lock index ce7218c7..88c6c1e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,12 +22,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -281,7 +275,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" dependencies = [ "ahash", - "allocator-api2", "serde", ] diff --git a/serde_with/Cargo.toml b/serde_with/Cargo.toml index 803986c3..6162d47a 100644 --- a/serde_with/Cargo.toml +++ b/serde_with/Cargo.toml @@ -54,6 +54,7 @@ chrono = ["chrono_0_4"] chrono_0_4 = ["dep:chrono_0_4"] guide = ["dep:doc-comment", "macros", "std"] hex = ["dep:hex", "alloc"] +hashbrown_0_14 = ["dep:hashbrown_0_14", "alloc"] indexmap = ["indexmap_1"] indexmap_1 = ["dep:indexmap_1", "alloc"] indexmap_2 = ["dep:indexmap_2", "alloc"] @@ -66,7 +67,7 @@ time_0_3 = ["dep:time_0_3"] base64 = {version = "0.21.0", optional = true, default-features = false} chrono_0_4 = {package = "chrono", version = "0.4.20", optional = true, default-features = false, features = ["serde"]} doc-comment = {version = "0.3.3", optional = true} -hashbrown = {version = "0.14.0", optional = true, features = ["serde"]} +hashbrown_0_14 = {package = "hashbrown", version = "0.14.0", optional = true, default-features = false, features = ["ahash", "serde"]} hex = {version = "0.4.3", optional = true, default-features = false} indexmap_1 = {package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"]} indexmap_2 = {package = "indexmap", version = "2.0", optional = true, default-features = false, features = ["serde"]} @@ -114,9 +115,9 @@ path = "tests/hex.rs" required-features = ["hex", "macros"] [[test]] -name = "hashbrown" -path = "tests/hashbrown.rs" -required-features = ["hashbrown", "macros"] +name = "hashbrown_0_14" +path = "tests/hashbrown_0_14.rs" +required-features = ["hashbrown_0_14", "macros"] [[test]] name = "indexmap_1" diff --git a/serde_with/src/de/duplicates.rs b/serde_with/src/de/duplicates.rs index 153f966e..8aa23592 100644 --- a/serde_with/src/de/duplicates.rs +++ b/serde_with/src/de/duplicates.rs @@ -7,8 +7,8 @@ use crate::{ prelude::*, MapFirstKeyWins, MapPreventDuplicates, SetLastValueWins, SetPreventDuplicates, }; -#[cfg(feature = "hashbrown")] -use hashbrown::{HashMap as HashbrownMap, HashSet as HashbrownSet}; +#[cfg(feature = "hashbrown_0_14")] +use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014}; #[cfg(feature = "indexmap_1")] use indexmap_1::{IndexMap, IndexSet}; #[cfg(feature = "indexmap_2")] diff --git a/serde_with/src/de/impls.rs b/serde_with/src/de/impls.rs index 627edde3..8c7026c8 100644 --- a/serde_with/src/de/impls.rs +++ b/serde_with/src/de/impls.rs @@ -1,6 +1,6 @@ use crate::{formats::*, prelude::*}; -#[cfg(feature = "hashbrown")] -use hashbrown::{HashMap as HashbrownMap, HashSet as HashbrownSet}; +#[cfg(feature = "hashbrown_0_14")] +use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014}; #[cfg(feature = "indexmap_1")] use indexmap_1::{IndexMap, IndexSet}; #[cfg(feature = "indexmap_2")] @@ -18,8 +18,8 @@ macro_rules! foreach_map { $m!(BTreeMap); #[cfg(feature = "std")] $m!(HashMap); - #[cfg(all(feature = "std", feature = "hashbrown"))] - $m!(HashbrownMap); + #[cfg(all(feature = "std", feature = "hashbrown_0_14"))] + $m!(HashbrownMap014); #[cfg(all(feature = "std", feature = "indexmap_1"))] $m!(IndexMap); #[cfg(all(feature = "std", feature = "indexmap_2"))] @@ -37,10 +37,10 @@ macro_rules! foreach_map_create { HashMap, (|size| HashMap::with_capacity_and_hasher(size, Default::default())) ); - #[cfg(feature = "hashbrown")] + #[cfg(feature = "hashbrown_0_14")] $m!( - HashbrownMap, - (|size| HashbrownMap::with_capacity_and_hasher(size, Default::default())) + HashbrownMap014, + (|size| HashbrownMap014::with_capacity_and_hasher(size, Default::default())) ); #[cfg(feature = "indexmap_1")] $m!( @@ -62,8 +62,8 @@ macro_rules! foreach_set { $m!(BTreeSet<(K, V): Ord>); #[cfg(feature = "std")] $m!(HashSet<(K, V): Eq + Hash>); - #[cfg(all(feature = "std", feature = "hashbrown"))] - $m!(HashbrownSet<(K, V): Eq + Hash>); + #[cfg(all(feature = "std", feature = "hashbrown_0_14"))] + $m!(HashbrownSet014<(K, V): Eq + Hash>); #[cfg(all(feature = "std", feature = "indexmap_1"))] $m!(IndexSet<(K, V): Eq + Hash>); #[cfg(all(feature = "std", feature = "indexmap_2"))] @@ -82,10 +82,10 @@ macro_rules! foreach_set_create { (|size| HashSet::with_capacity_and_hasher(size, S::default())), insert ); - #[cfg(feature = "hashbrown")] + #[cfg(feature = "hashbrown_0_14")] $m!( - HashbrownSet, - (|size| HashbrownSet::with_capacity_and_hasher(size, S::default())), + HashbrownSet014, + (|size| HashbrownSet014::with_capacity_and_hasher(size, S::default())), insert ); #[cfg(feature = "indexmap_1")] diff --git a/serde_with/src/duplicate_key_impls/error_on_duplicate.rs b/serde_with/src/duplicate_key_impls/error_on_duplicate.rs index 673e7660..715c2153 100644 --- a/serde_with/src/duplicate_key_impls/error_on_duplicate.rs +++ b/serde_with/src/duplicate_key_impls/error_on_duplicate.rs @@ -34,8 +34,8 @@ where } } -#[cfg(feature = "hashbrown")] -impl PreventDuplicateInsertsSet for hashbrown::HashSet +#[cfg(feature = "hashbrown_0_14")] +impl PreventDuplicateInsertsSet for hashbrown_0_14::HashSet where T: Eq + Hash, S: BuildHasher + Default, @@ -129,8 +129,8 @@ where } } -#[cfg(feature = "hashbrown")] -impl PreventDuplicateInsertsMap for hashbrown::HashMap +#[cfg(feature = "hashbrown_0_14")] +impl PreventDuplicateInsertsMap for hashbrown_0_14::HashMap where K: Eq + Hash, S: BuildHasher + Default, diff --git a/serde_with/src/duplicate_key_impls/first_value_wins.rs b/serde_with/src/duplicate_key_impls/first_value_wins.rs index 33035b9a..e2413e6b 100644 --- a/serde_with/src/duplicate_key_impls/first_value_wins.rs +++ b/serde_with/src/duplicate_key_impls/first_value_wins.rs @@ -35,8 +35,8 @@ where } } -#[cfg(feature = "hashbrown")] -impl DuplicateInsertsFirstWinsMap for hashbrown::HashMap +#[cfg(feature = "hashbrown_0_14")] +impl DuplicateInsertsFirstWinsMap for hashbrown_0_14::HashMap where K: Eq + Hash, S: BuildHasher + Default, @@ -51,7 +51,7 @@ where #[inline] fn insert(&mut self, key: K, value: V) { - use hashbrown::hash_map::Entry; + use hashbrown_0_14::hash_map::Entry; match self.entry(key) { // we want to keep the first value, so do nothing diff --git a/serde_with/src/duplicate_key_impls/last_value_wins.rs b/serde_with/src/duplicate_key_impls/last_value_wins.rs index e1139545..970197aa 100644 --- a/serde_with/src/duplicate_key_impls/last_value_wins.rs +++ b/serde_with/src/duplicate_key_impls/last_value_wins.rs @@ -28,8 +28,8 @@ where } } -#[cfg(feature = "hashbrown")] -impl DuplicateInsertsLastWinsSet for hashbrown::HashSet +#[cfg(feature = "hashbrown_0_14")] +impl DuplicateInsertsLastWinsSet for hashbrown_0_14::HashSet where T: Eq + Hash, S: BuildHasher + Default, diff --git a/serde_with/src/guide/feature_flags.md b/serde_with/src/guide/feature_flags.md index 5768a76a..201625d1 100644 --- a/serde_with/src/guide/feature_flags.md +++ b/serde_with/src/guide/feature_flags.md @@ -6,19 +6,18 @@ Each entry will explain the feature in more detail. `serde_with` is fully `no_std` compatible. Using it in a `no_std` environment requires using `default-features = false`, since `std` is enabled by default. -- [Available Feature Flags](#available-feature-flags) - - [`alloc`](#alloc) - - [`std` (default)](#std-default) - - [`base64`](#base64) - - [`chrono_0_4`](#chrono_0_4) - - [`guide`](#guide) - - [`hashbrown`](#hashbrown) - - [`hex`](#hex) - - [`indexmap_1`](#indexmap_1) - - [`indexmap_2`](#indexmap_2) - - [`json`](#json) - - [`macros` (default)](#macros-default) - - [`time_0_3`](#time_0_3) +1. [`alloc`](#alloc) +2. [`std` (default)](#std-default) +3. [`base64`](#base64) +4. [`chrono_0_4`](#chrono_0_4) +5. [`guide`](#guide) +6. [`hashbrown_0_14`](#hashbrown_0_14) +7. [`hex`](#hex) +8. [`indexmap_1`](#indexmap_1) +9. [`indexmap_2`](#indexmap_2) +10. [`json`](#json) +11. [`macros` (default)](#macros-default) +12. [`time_0_3`](#time_0_3) ## `alloc` @@ -51,11 +50,11 @@ This pulls in `chrono` v0.4 as a dependency. The `guide` feature enables inclusion of this user guide. The feature only changes the rustdoc output and enables no other effects. -## `hashbrown` +## `hashbrown_0_14` -The `hashbrown` feature enables `hashbown::{HashMap, HashSet}` as supported containers. +The `hashbrown_0_14` feature enables `hashbown::{HashMap, HashSet}` as supported containers. -This pulls in `hashbrown` as a dependency. +This pulls in `hashbrown` v0.14 as a dependency. It enables the `alloc` feature. Some functionality is only available when `std` is enabled too. diff --git a/serde_with/src/ser/duplicates.rs b/serde_with/src/ser/duplicates.rs index cef3bd9b..fb765d55 100644 --- a/serde_with/src/ser/duplicates.rs +++ b/serde_with/src/ser/duplicates.rs @@ -2,8 +2,8 @@ use super::impls::{foreach_map, foreach_set}; use crate::{ prelude::*, MapFirstKeyWins, MapPreventDuplicates, SetLastValueWins, SetPreventDuplicates, }; -#[cfg(feature = "hashbrown")] -use hashbrown::{HashMap as HashbrownMap, HashSet as HashbrownSet}; +#[cfg(feature = "hashbrown_0_14")] +use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014}; #[cfg(feature = "indexmap_1")] use indexmap_1::{IndexMap, IndexSet}; #[cfg(feature = "indexmap_2")] diff --git a/serde_with/src/ser/impls.rs b/serde_with/src/ser/impls.rs index 4f62990e..c6c37dd1 100644 --- a/serde_with/src/ser/impls.rs +++ b/serde_with/src/ser/impls.rs @@ -1,6 +1,6 @@ use crate::{formats, formats::Strictness, prelude::*}; -#[cfg(feature = "hashbrown")] -use hashbrown::{HashMap as HashbrownMap, HashSet as HashbrownSet}; +#[cfg(feature = "hashbrown_0_14")] +use hashbrown_0_14::{HashMap as HashbrownMap014, HashSet as HashbrownSet014}; #[cfg(feature = "indexmap_1")] use indexmap_1::{IndexMap, IndexSet}; #[cfg(feature = "indexmap_2")] @@ -19,8 +19,8 @@ macro_rules! foreach_map { $m!(BTreeMap); #[cfg(feature = "std")] $m!(HashMap); - #[cfg(feature = "hashbrown")] - $m!(HashbrownMap); + #[cfg(feature = "hashbrown_0_14")] + $m!(HashbrownMap014); #[cfg(feature = "indexmap_1")] $m!(IndexMap); #[cfg(feature = "indexmap_2")] @@ -35,8 +35,8 @@ macro_rules! foreach_set { $m!(BTreeSet<$T>); #[cfg(feature = "std")] $m!(HashSet<$T, H: Sized>); - #[cfg(feature = "hashbrown")] - $m!(HashbrownSet<$T, H: Sized>); + #[cfg(feature = "hashbrown_0_14")] + $m!(HashbrownSet014<$T, H: Sized>); #[cfg(feature = "indexmap_1")] $m!(IndexSet<$T, H: Sized>); #[cfg(feature = "indexmap_2")] diff --git a/serde_with/tests/hashbrown.rs b/serde_with/tests/hashbrown_0_14.rs similarity index 99% rename from serde_with/tests/hashbrown.rs rename to serde_with/tests/hashbrown_0_14.rs index 00f39adb..1f4039bd 100644 --- a/serde_with/tests/hashbrown.rs +++ b/serde_with/tests/hashbrown_0_14.rs @@ -11,7 +11,7 @@ mod utils; use crate::utils::{check_deserialization, check_error_deserialization, is_equal}; use core::iter::FromIterator; use expect_test::expect; -use hashbrown::{HashMap, HashSet}; +use hashbrown_0_14::{HashMap, HashSet}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr, Same}; use std::net::IpAddr;