Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk committed Aug 15, 2023
1 parent 96bd441 commit c0af576
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions serde_with/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]}
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions serde_with/src/de/duplicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
24 changes: 12 additions & 12 deletions serde_with/src/de/impls.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -18,8 +18,8 @@ macro_rules! foreach_map {
$m!(BTreeMap<K: Ord, V>);
#[cfg(feature = "std")]
$m!(HashMap<K: Eq + Hash, V, H: Sized>);
#[cfg(all(feature = "std", feature = "hashbrown"))]
$m!(HashbrownMap<K: Eq + Hash, V, H: Sized>);
#[cfg(all(feature = "std", feature = "hashbrown_0_14"))]
$m!(HashbrownMap014<K: Eq + Hash, V, H: Sized>);
#[cfg(all(feature = "std", feature = "indexmap_1"))]
$m!(IndexMap<K: Eq + Hash, V, H: Sized>);
#[cfg(all(feature = "std", feature = "indexmap_2"))]
Expand All @@ -37,10 +37,10 @@ macro_rules! foreach_map_create {
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
(|size| HashMap::with_capacity_and_hasher(size, Default::default()))
);
#[cfg(feature = "hashbrown")]
#[cfg(feature = "hashbrown_0_14")]
$m!(
HashbrownMap<K: Eq + Hash, V, S: BuildHasher + Default>,
(|size| HashbrownMap::with_capacity_and_hasher(size, Default::default()))
HashbrownMap014<K: Eq + Hash, V, S: BuildHasher + Default>,
(|size| HashbrownMap014::with_capacity_and_hasher(size, Default::default()))
);
#[cfg(feature = "indexmap_1")]
$m!(
Expand All @@ -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"))]
Expand All @@ -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<T: Eq + Hash, S: BuildHasher + Default>,
(|size| HashbrownSet::with_capacity_and_hasher(size, S::default())),
HashbrownSet014<T: Eq + Hash, S: BuildHasher + Default>,
(|size| HashbrownSet014::with_capacity_and_hasher(size, S::default())),
insert
);
#[cfg(feature = "indexmap_1")]
Expand Down
8 changes: 4 additions & 4 deletions serde_with/src/duplicate_key_impls/error_on_duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ where
}
}

#[cfg(feature = "hashbrown")]
impl<T, S> PreventDuplicateInsertsSet<T> for hashbrown::HashSet<T, S>
#[cfg(feature = "hashbrown_0_14")]
impl<T, S> PreventDuplicateInsertsSet<T> for hashbrown_0_14::HashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher + Default,
Expand Down Expand Up @@ -129,8 +129,8 @@ where
}
}

#[cfg(feature = "hashbrown")]
impl<K, V, S> PreventDuplicateInsertsMap<K, V> for hashbrown::HashMap<K, V, S>
#[cfg(feature = "hashbrown_0_14")]
impl<K, V, S> PreventDuplicateInsertsMap<K, V> for hashbrown_0_14::HashMap<K, V, S>
where
K: Eq + Hash,
S: BuildHasher + Default,
Expand Down
6 changes: 3 additions & 3 deletions serde_with/src/duplicate_key_impls/first_value_wins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ where
}
}

#[cfg(feature = "hashbrown")]
impl<K, V, S> DuplicateInsertsFirstWinsMap<K, V> for hashbrown::HashMap<K, V, S>
#[cfg(feature = "hashbrown_0_14")]
impl<K, V, S> DuplicateInsertsFirstWinsMap<K, V> for hashbrown_0_14::HashMap<K, V, S>
where
K: Eq + Hash,
S: BuildHasher + Default,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions serde_with/src/duplicate_key_impls/last_value_wins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ where
}
}

#[cfg(feature = "hashbrown")]
impl<T, S> DuplicateInsertsLastWinsSet<T> for hashbrown::HashSet<T, S>
#[cfg(feature = "hashbrown_0_14")]
impl<T, S> DuplicateInsertsLastWinsSet<T> for hashbrown_0_14::HashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher + Default,
Expand Down
31 changes: 15 additions & 16 deletions serde_with/src/guide/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions serde_with/src/ser/duplicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
12 changes: 6 additions & 6 deletions serde_with/src/ser/impls.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -19,8 +19,8 @@ macro_rules! foreach_map {
$m!(BTreeMap<K, V>);
#[cfg(feature = "std")]
$m!(HashMap<K, V, H: Sized>);
#[cfg(feature = "hashbrown")]
$m!(HashbrownMap<K, V, H: Sized>);
#[cfg(feature = "hashbrown_0_14")]
$m!(HashbrownMap014<K, V, H: Sized>);
#[cfg(feature = "indexmap_1")]
$m!(IndexMap<K, V, H: Sized>);
#[cfg(feature = "indexmap_2")]
Expand All @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c0af576

Please sign in to comment.