From 73e5eca5261bec09ff21b216409149283adfee0a Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Thu, 12 Sep 2024 07:47:52 -0400 Subject: [PATCH] Remove rkyv support Support will instead be directly provided by the `rkyv` crate via an optional feature. --- Cargo.toml | 4 - README.md | 1 - src/external_trait_impls/mod.rs | 2 - src/external_trait_impls/rkyv/hash_map.rs | 125 ---------------------- src/external_trait_impls/rkyv/hash_set.rs | 123 --------------------- src/external_trait_impls/rkyv/mod.rs | 2 - 6 files changed, 257 deletions(-) delete mode 100644 src/external_trait_impls/rkyv/hash_map.rs delete mode 100644 src/external_trait_impls/rkyv/hash_set.rs delete mode 100644 src/external_trait_impls/rkyv/mod.rs diff --git a/Cargo.toml b/Cargo.toml index c5843125d..8b5ed89ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,6 @@ ahash = { version = "0.8.7", 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 } -rkyv = { version = "0.7.42", optional = true, default-features = false, features = [ - "alloc", -] } borsh = { version = "1.5.0", default-features = false, optional = true, features = ["derive"]} # When built as part of libstd @@ -45,7 +42,6 @@ fnv = "1.0.7" serde_test = "1.0" doc-comment = "0.3.1" bumpalo = { version = "3.13.0", features = ["allocator-api2"] } -rkyv = { version = "0.7.42", features = ["validation"] } [features] default = ["default-hasher", "inline-more", "allocator-api2", "equivalent", "raw-entry"] diff --git a/README.md b/README.md index de4133d75..578a8ef94 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,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. -- `rkyv`: Enables rkyv serialization support. - `rayon`: Enables rayon parallel iterator support. - `equivalent`: Allows comparisons to be customized with the `Equivalent` trait. - `raw-entry`: Enables access to the deprecated `RawEntry` API. diff --git a/src/external_trait_impls/mod.rs b/src/external_trait_impls/mod.rs index 452736f28..bca8f9770 100644 --- a/src/external_trait_impls/mod.rs +++ b/src/external_trait_impls/mod.rs @@ -2,7 +2,5 @@ mod borsh; #[cfg(feature = "rayon")] pub(crate) mod rayon; -#[cfg(feature = "rkyv")] -mod rkyv; #[cfg(feature = "serde")] mod serde; diff --git a/src/external_trait_impls/rkyv/hash_map.rs b/src/external_trait_impls/rkyv/hash_map.rs deleted file mode 100644 index fae7f7676..000000000 --- a/src/external_trait_impls/rkyv/hash_map.rs +++ /dev/null @@ -1,125 +0,0 @@ -use crate::HashMap; -use core::{ - borrow::Borrow, - hash::{BuildHasher, Hash}, -}; -use rkyv::{ - collections::hash_map::{ArchivedHashMap, HashMapResolver}, - ser::{ScratchSpace, Serializer}, - Archive, Deserialize, Fallible, Serialize, -}; - -impl Archive for HashMap -where - K::Archived: Hash + Eq, -{ - type Archived = ArchivedHashMap; - type Resolver = HashMapResolver; - - #[inline] - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - ArchivedHashMap::resolve_from_len(self.len(), pos, resolver, out); - } -} - -impl Serialize for HashMap -where - K: Serialize + Hash + Eq, - K::Archived: Hash + Eq, - V: Serialize, - S: Serializer + ScratchSpace + ?Sized, -{ - #[inline] - fn serialize(&self, serializer: &mut S) -> Result { - unsafe { ArchivedHashMap::serialize_from_iter(self.iter(), serializer) } - } -} - -impl - Deserialize, D> for ArchivedHashMap -where - K::Archived: Deserialize + Hash + Eq, - V::Archived: Deserialize, -{ - #[inline] - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - let mut result = HashMap::with_capacity_and_hasher(self.len(), S::default()); - for (k, v) in self.iter() { - result.insert(k.deserialize(deserializer)?, v.deserialize(deserializer)?); - } - Ok(result) - } -} - -impl, V, AK: Hash + Eq, AV: PartialEq, S: BuildHasher> - PartialEq> for ArchivedHashMap -{ - #[inline] - fn eq(&self, other: &HashMap) -> bool { - if self.len() != other.len() { - false - } else { - self.iter() - .all(|(key, value)| other.get(key).map_or(false, |v| value.eq(v))) - } - } -} - -impl, V, AK: Hash + Eq, AV: PartialEq> - PartialEq> for HashMap -{ - #[inline] - fn eq(&self, other: &ArchivedHashMap) -> bool { - other.eq(self) - } -} - -#[cfg(test)] -mod tests { - use crate::HashMap; - use alloc::string::String; - use rkyv::{ - archived_root, check_archived_root, - ser::{serializers::AllocSerializer, Serializer}, - Deserialize, Infallible, - }; - - #[test] - fn index_map() { - let mut value = HashMap::new(); - value.insert(String::from("foo"), 10); - value.insert(String::from("bar"), 20); - value.insert(String::from("baz"), 40); - value.insert(String::from("bat"), 80); - - let mut serializer = AllocSerializer::<4096>::default(); - serializer.serialize_value(&value).unwrap(); - let result = serializer.into_serializer().into_inner(); - let archived = unsafe { archived_root::>(result.as_ref()) }; - - assert_eq!(value.len(), archived.len()); - for (k, v) in value.iter() { - let (ak, av) = archived.get_key_value(k.as_str()).unwrap(); - assert_eq!(k, ak); - assert_eq!(v, av); - } - - let deserialized: HashMap = archived.deserialize(&mut Infallible).unwrap(); - assert_eq!(value, deserialized); - } - - #[test] - fn validate_index_map() { - let mut value = HashMap::new(); - value.insert(String::from("foo"), 10); - value.insert(String::from("bar"), 20); - value.insert(String::from("baz"), 40); - value.insert(String::from("bat"), 80); - - let mut serializer = AllocSerializer::<4096>::default(); - serializer.serialize_value(&value).unwrap(); - let result = serializer.into_serializer().into_inner(); - check_archived_root::>(result.as_ref()) - .expect("failed to validate archived index map"); - } -} diff --git a/src/external_trait_impls/rkyv/hash_set.rs b/src/external_trait_impls/rkyv/hash_set.rs deleted file mode 100644 index c8a69cf4f..000000000 --- a/src/external_trait_impls/rkyv/hash_set.rs +++ /dev/null @@ -1,123 +0,0 @@ -use crate::HashSet; -use core::{ - borrow::Borrow, - hash::{BuildHasher, Hash}, -}; -use rkyv::{ - collections::hash_set::{ArchivedHashSet, HashSetResolver}, - ser::{ScratchSpace, Serializer}, - Archive, Deserialize, Fallible, Serialize, -}; - -impl Archive for HashSet -where - K::Archived: Hash + Eq, -{ - type Archived = ArchivedHashSet; - type Resolver = HashSetResolver; - - #[inline] - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - ArchivedHashSet::::resolve_from_len(self.len(), pos, resolver, out); - } -} - -impl Serialize for HashSet -where - K::Archived: Hash + Eq, - K: Serialize + Hash + Eq, - S: ScratchSpace + Serializer + ?Sized, -{ - #[inline] - fn serialize(&self, serializer: &mut S) -> Result { - unsafe { ArchivedHashSet::serialize_from_iter(self.iter(), serializer) } - } -} - -impl Deserialize, D> for ArchivedHashSet -where - K: Archive + Hash + Eq, - K::Archived: Deserialize + Hash + Eq, - D: Fallible + ?Sized, - S: Default + BuildHasher, -{ - #[inline] - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - let mut result = HashSet::with_hasher(S::default()); - for k in self.iter() { - result.insert(k.deserialize(deserializer)?); - } - Ok(result) - } -} - -impl, AK: Hash + Eq, S: BuildHasher> PartialEq> - for ArchivedHashSet -{ - #[inline] - fn eq(&self, other: &HashSet) -> bool { - if self.len() != other.len() { - false - } else { - self.iter().all(|key| other.get(key).is_some()) - } - } -} - -impl, AK: Hash + Eq, S: BuildHasher> PartialEq> - for HashSet -{ - #[inline] - fn eq(&self, other: &ArchivedHashSet) -> bool { - other.eq(self) - } -} - -#[cfg(test)] -mod tests { - use crate::HashSet; - use alloc::string::String; - use rkyv::{ - archived_root, check_archived_root, - ser::{serializers::AllocSerializer, Serializer}, - Deserialize, Infallible, - }; - - #[test] - fn index_set() { - let mut value = HashSet::new(); - value.insert(String::from("foo")); - value.insert(String::from("bar")); - value.insert(String::from("baz")); - value.insert(String::from("bat")); - - let mut serializer = AllocSerializer::<4096>::default(); - serializer.serialize_value(&value).unwrap(); - let result = serializer.into_serializer().into_inner(); - let archived = unsafe { archived_root::>(result.as_ref()) }; - - assert_eq!(value.len(), archived.len()); - for k in value.iter() { - let ak = archived.get(k.as_str()).unwrap(); - assert_eq!(k, ak); - } - - let deserialized: HashSet = archived.deserialize(&mut Infallible).unwrap(); - assert_eq!(value, deserialized); - } - - #[test] - fn validate_index_set() { - let mut value = HashSet::new(); - value.insert(String::from("foo")); - value.insert(String::from("bar")); - value.insert(String::from("baz")); - value.insert(String::from("bat")); - - let mut serializer = AllocSerializer::<4096>::default(); - serializer.serialize_value(&value).unwrap(); - let result = serializer.into_serializer().into_inner(); - check_archived_root::>(result.as_ref()) - .expect("failed to validate archived index set"); - } -} diff --git a/src/external_trait_impls/rkyv/mod.rs b/src/external_trait_impls/rkyv/mod.rs deleted file mode 100644 index 2bde6a065..000000000 --- a/src/external_trait_impls/rkyv/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod hash_map; -mod hash_set;