From 334b57341804266153da7d40e62ee89c429cb0f2 Mon Sep 17 00:00:00 2001 From: kirk Date: Tue, 28 May 2024 23:10:45 +0000 Subject: [PATCH] remove hashbrown --- Cargo.toml | 3 +-- derive/Cargo.toml | 5 +---- src/serde_bin.rs | 24 +++++++++++------------- src/serde_json.rs | 24 +++++++++++------------- src/serde_ron.rs | 24 +++++++++++------------- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acc7b4c..ff100ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ json = ["dep:nanoserde-derive", "nanoserde-derive/json"] binary = ["dep:nanoserde-derive", "nanoserde-derive/binary"] ron = ["dep:nanoserde-derive", "nanoserde-derive/ron"] toml = [] -no_std = ["dep:hashbrown"] +no_std = [] [dependencies] -hashbrown = { version = "0.14", optional = true, default-features = false, features = ["ahash"] } nanoserde-derive = { path = "derive", version = "=0.2.0", optional = true } diff --git a/derive/Cargo.toml b/derive/Cargo.toml index f123d5b..ceff924 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -14,7 +14,4 @@ default = [] json = [] binary = [] ron = [] -no_std = ["dep:hashbrown"] - -[dependencies] -hashbrown = { version = "0.14", optional = true, default-features = false, features = ["ahash"] } +no_std = [] diff --git a/src/serde_bin.rs b/src/serde_bin.rs index 93e0a1c..e770b53 100644 --- a/src/serde_bin.rs +++ b/src/serde_bin.rs @@ -7,12 +7,6 @@ use alloc::collections::{BTreeSet, LinkedList}; use alloc::string::String; use alloc::vec::Vec; -#[cfg(feature = "no_std")] -use hashbrown::{HashMap, HashSet}; - -#[cfg(not(feature = "no_std"))] -use std::collections::{HashMap, HashSet}; - /// A trait for objects that can be serialized to binary. pub trait SerBin { /// Serialize Self to bytes. @@ -294,7 +288,8 @@ where } } -impl SerBin for HashSet +#[cfg(not(feature = "no_std"))] +impl SerBin for std::collections::HashSet where T: SerBin, { @@ -307,13 +302,14 @@ where } } -impl DeBin for HashSet +#[cfg(not(feature = "no_std"))] +impl DeBin for std::collections::HashSet where T: DeBin + Hash + Eq, { - fn de_bin(o: &mut usize, d: &[u8]) -> Result, DeBinErr> { + fn de_bin(o: &mut usize, d: &[u8]) -> Result { let len: usize = DeBin::de_bin(o, d)?; - let mut out = HashSet::with_capacity(len); + let mut out = std::collections::HashSet::with_capacity(len); for _ in 0..len { out.insert(DeBin::de_bin(o, d)?); } @@ -534,7 +530,8 @@ where } } -impl SerBin for HashMap +#[cfg(not(feature = "no_std"))] +impl SerBin for std::collections::HashMap where K: SerBin, V: SerBin, @@ -549,14 +546,15 @@ where } } -impl DeBin for HashMap +#[cfg(not(feature = "no_std"))] +impl DeBin for std::collections::HashMap where K: DeBin + core::cmp::Eq + Hash, V: DeBin, { fn de_bin(o: &mut usize, d: &[u8]) -> Result { let len: usize = DeBin::de_bin(o, d)?; - let mut h = HashMap::with_capacity(len); + let mut h = std::collections::HashMap::with_capacity(len); for _ in 0..len { let k = DeBin::de_bin(o, d)?; let v = DeBin::de_bin(o, d)?; diff --git a/src/serde_json.rs b/src/serde_json.rs index 6f3139e..1f2be1a 100644 --- a/src/serde_json.rs +++ b/src/serde_json.rs @@ -7,12 +7,6 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; -#[cfg(feature = "no_std")] -use hashbrown::{HashMap, HashSet}; - -#[cfg(not(feature = "no_std"))] -use std::collections::{HashMap, HashSet}; - /// The internal state of a JSON serialization. pub struct SerJsonState { pub out: String, @@ -885,7 +879,8 @@ where } } -impl SerJson for HashSet +#[cfg(not(feature = "no_std"))] +impl SerJson for std::collections::HashSet where T: SerJson, { @@ -905,12 +900,13 @@ where } } -impl DeJson for HashSet +#[cfg(not(feature = "no_std"))] +impl DeJson for std::collections::HashSet where T: DeJson + Hash + Eq, { - fn de_json(s: &mut DeJsonState, i: &mut Chars) -> Result, DeJsonErr> { - let mut out = HashSet::new(); + fn de_json(s: &mut DeJsonState, i: &mut Chars) -> Result { + let mut out = std::collections::HashSet::new(); s.block_open(i)?; while s.tok != DeJsonTok::BlockClose { @@ -1177,7 +1173,8 @@ where } } -impl SerJson for HashMap +#[cfg(not(feature = "no_std"))] +impl SerJson for std::collections::HashMap where K: SerJson, V: SerJson, @@ -1201,13 +1198,14 @@ where } } -impl DeJson for HashMap +#[cfg(not(feature = "no_std"))] +impl DeJson for std::collections::HashMap where K: DeJson + Eq + Hash, V: DeJson, { fn de_json(s: &mut DeJsonState, i: &mut Chars) -> Result { - let mut h = HashMap::new(); + let mut h = std::collections::HashMap::new(); s.curly_open(i)?; while s.tok != DeJsonTok::CurlyClose { let k = DeJson::de_json(s, i)?; diff --git a/src/serde_ron.rs b/src/serde_ron.rs index ba7b049..2c180e8 100644 --- a/src/serde_ron.rs +++ b/src/serde_ron.rs @@ -7,12 +7,6 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; -#[cfg(feature = "no_std")] -use hashbrown::{HashMap, HashSet}; - -#[cfg(not(feature = "no_std"))] -use std::collections::{HashMap, HashSet}; - /// The internal state of a RON serialization. pub struct SerRonState { pub out: String, @@ -883,7 +877,8 @@ where } } -impl SerRon for HashSet +#[cfg(not(feature = "no_std"))] +impl SerRon for std::collections::HashSet where T: SerRon, { @@ -903,12 +898,13 @@ where } } -impl DeRon for HashSet +#[cfg(not(feature = "no_std"))] +impl DeRon for std::collections::HashSet where T: DeRon + Hash + Eq, { - fn de_ron(s: &mut DeRonState, i: &mut Chars) -> Result, DeRonErr> { - let mut out = HashSet::new(); + fn de_ron(s: &mut DeRonState, i: &mut Chars) -> Result { + let mut out = std::collections::HashSet::new(); s.block_open(i)?; while s.tok != DeRonTok::BlockClose { @@ -1189,7 +1185,8 @@ where } } -impl SerRon for HashMap +#[cfg(not(feature = "no_std"))] +impl SerRon for std::collections::HashMap where K: SerRon, V: SerRon, @@ -1208,13 +1205,14 @@ where } } -impl DeRon for HashMap +#[cfg(not(feature = "no_std"))] +impl DeRon for std::collections::HashMap where K: DeRon + Eq + Hash, V: DeRon, { fn de_ron(s: &mut DeRonState, i: &mut Chars) -> Result { - let mut h = HashMap::new(); + let mut h = std::collections::HashMap::new(); s.curly_open(i)?; while s.tok != DeRonTok::CurlyClose { let k = DeRon::de_ron(s, i)?;