add support for arbitrary

This commit is contained in:
Joel Wejdenstål 2023-07-11 05:00:57 +02:00
parent d36311e634
commit a483a4c7d8
No known key found for this signature in database
GPG Key ID: DF03CEFBB1A915AA
4 changed files with 18 additions and 0 deletions

View File

@ -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"]

View File

@ -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!

13
src/arbitrary.rs Normal file
View File

@ -0,0 +1,13 @@
use arbitrary::{Arbitrary, Unstructured};
use core::hash::BuildHasher;
impl<'a, K, V, S> Arbitrary<'a> for crate::DashMap<K, V, S>
where
K: Eq + std::hash::Hash + Arbitrary<'a>,
V: Arbitrary<'a>,
S: Default + BuildHasher + Clone,
{
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary_iter()?.collect()
}
}

View File

@ -1,5 +1,7 @@
#![allow(clippy::type_complexity)]
#[cfg(feature = "arbitrary")]
mod arbitrary;
pub mod iter;
pub mod iter_set;
mod lock;