diff --git a/Cargo.toml b/Cargo.toml index d37c74aec..a33a6913d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ foldhash = { version = "0.1.2", default-features = false, optional = true } # For external trait impls rayon = { version = "1.0", optional = true } serde = { version = "1.0.25", default-features = false, optional = true } -borsh = { version = "1.5.0", default-features = false, optional = true, features = ["derive"]} # When built as part of libstd core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } diff --git a/README.md b/README.md index 1b1aafb64..cb6dc2695 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,6 @@ This crate has the following Cargo features: - `nightly`: Enables nightly-only features including: `#[may_dangle]`. - `serde`: Enables serde serialization support. -- `borsh`: Enables borsh serialization support. - `rayon`: Enables rayon parallel iterator support. - `equivalent`: Allows comparisons to be customized with the `Equivalent` trait. (enabled by default) - `raw-entry`: Enables access to the deprecated `RawEntry` API. diff --git a/src/external_trait_impls/borsh/hash_map.rs b/src/external_trait_impls/borsh/hash_map.rs deleted file mode 100644 index 8991affbc..000000000 --- a/src/external_trait_impls/borsh/hash_map.rs +++ /dev/null @@ -1,78 +0,0 @@ -use crate::HashMap; - -use borsh::{ - io::{Read, Result, Write}, - BorshDeserialize, BorshSerialize, -}; - -impl BorshSerialize for HashMap { - fn serialize(&self, writer: &mut W) -> Result<()> { - // assuming hash may have some seed, - // as borsh is supposed by default to be deterministic, need to write it down - // if allocator is compile time, than one can just impl wrapper with zero bytes serde of it - self.hash_builder.serialize(writer)?; - // considering A stateless - self.len().serialize(writer)?; - for kv in self.iter() { - kv.serialize(writer)?; - } - Ok(()) - } -} - -impl< - K: BorshDeserialize + core::hash::Hash + Eq, - V: BorshDeserialize, - S: BorshDeserialize + core::hash::BuildHasher, - > BorshDeserialize for HashMap -{ - fn deserialize_reader(reader: &mut R) -> Result { - let hash_builder = S::deserialize_reader(reader)?; - let len = usize::deserialize_reader(reader)?; - let mut map = HashMap::with_capacity_and_hasher(len, hash_builder); - for _ in 0..len { - let (k, v) = <(K, V)>::deserialize_reader(reader)?; - // can use raw api here to init from memory, so can do it other time - map.insert(k, v); - } - Ok(map) - } -} - -#[cfg(test)] -mod tests { - use borsh::{BorshDeserialize, BorshSerialize}; - use std::vec::Vec; - - #[derive(Default, BorshDeserialize, BorshSerialize, Clone)] - struct NoHash; - - impl core::hash::BuildHasher for NoHash { - type Hasher = NoHash; - fn build_hasher(&self) -> NoHash { - Self - } - } - - impl core::hash::Hasher for NoHash { - fn finish(&self) -> u64 { - 42 - } - - fn write(&mut self, _bytes: &[u8]) {} - } - - #[test] - fn encdec() { - let mut map = crate::HashMap::<_, _, NoHash>::default(); - map.insert(1, 2); - map.insert(3, 4); - let mut buf = Vec::new(); - map.serialize(&mut buf).unwrap(); - let original = map.clone(); - map = crate::HashMap::<_, _, NoHash>::deserialize_reader(&mut &buf[..]).unwrap(); - assert_eq!(original[&1], map[&1]); - assert_eq!(original[&3], map[&3]); - assert_eq!(original.len(), map.len()); - } -} diff --git a/src/external_trait_impls/borsh/mod.rs b/src/external_trait_impls/borsh/mod.rs deleted file mode 100644 index 841e4b1a2..000000000 --- a/src/external_trait_impls/borsh/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod hash_map; diff --git a/src/external_trait_impls/mod.rs b/src/external_trait_impls/mod.rs index bca8f9770..ef497836c 100644 --- a/src/external_trait_impls/mod.rs +++ b/src/external_trait_impls/mod.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "borsh")] -mod borsh; #[cfg(feature = "rayon")] pub(crate) mod rayon; #[cfg(feature = "serde")]