From a483a4c7d8d80c91e0257c69333010cb107ffd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Tue, 11 Jul 2023 05:00:57 +0200 Subject: [PATCH] add support for arbitrary --- Cargo.toml | 1 + README.md | 2 ++ src/arbitrary.rs | 13 +++++++++++++ src/lib.rs | 2 ++ 4 files changed, 18 insertions(+) create mode 100644 src/arbitrary.rs diff --git a/Cargo.toml b/Cargo.toml index 74a00e8..268b5b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ serde = { version = "1.0.171", optional = true, features = ["derive"] } cfg-if = "1.0.0" rayon = { version = "1.7.0", optional = true } once_cell = "1.18.0" +arbitrary = { version = "1.3.0", optional = true } [package.metadata.docs.rs] features = ["rayon", "raw-api", "serde"] diff --git a/README.md b/README.md index 1de225a..20b9f85 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ If you have any suggestions or tips do not hesitate to open an issue or a PR. - `inline` - Enables `inline-more` feature from the `hashbrown` crate. Can lead to better performance, but with the cost of longer compile-time. +- `arbitrary` - Enables support for the `arbitrary` crate. + ## Contributing DashMap gladly accepts contributions! diff --git a/src/arbitrary.rs b/src/arbitrary.rs new file mode 100644 index 0000000..a760964 --- /dev/null +++ b/src/arbitrary.rs @@ -0,0 +1,13 @@ +use arbitrary::{Arbitrary, Unstructured}; +use core::hash::BuildHasher; + +impl<'a, K, V, S> Arbitrary<'a> for crate::DashMap +where + K: Eq + std::hash::Hash + Arbitrary<'a>, + V: Arbitrary<'a>, + S: Default + BuildHasher + Clone, +{ + fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { + u.arbitrary_iter()?.collect() + } +} diff --git a/src/lib.rs b/src/lib.rs index 9f96b96..ff64e87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![allow(clippy::type_complexity)] +#[cfg(feature = "arbitrary")] +mod arbitrary; pub mod iter; pub mod iter_set; mod lock;