From 184c2874d9bae11749638ee8b15dede93dd33d4f Mon Sep 17 00:00:00 2001 From: Brooklyn Zelenka Date: Wed, 26 Jun 2024 13:58:38 -0700 Subject: [PATCH] feat: derive Arbitrary for `multihash_codetable::Code` (#366) --- codetable/Cargo.toml | 2 ++ codetable/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/codetable/Cargo.toml b/codetable/Cargo.toml index e81ebbfe..ae892b4a 100644 --- a/codetable/Cargo.toml +++ b/codetable/Cargo.toml @@ -11,6 +11,7 @@ edition = "2021" [features] default = ["std"] std = ["blake2b_simd?/std", "blake2s_simd?/std", "blake3?/std", "digest?/std", "sha1?/std", "sha2?/std", "sha3?/std", "strobe-rs?/std", "ripemd?/std", "multihash-derive/std", "core2/std"] +arb = ["dep:arbitrary", "std"] sha1 = ["dep:digest", "dep:sha1"] sha2 = ["dep:digest", "dep:sha2"] sha3 = ["dep:digest", "dep:sha3"] @@ -33,6 +34,7 @@ ripemd = { version = "0.1.1", default-features = false, optional = true } multihash-derive = { version = "0.9.0", path = "../derive", default-features = false } core2 = { version = "0.4.0", default-features = false } serde = { version = "1.0.158", features = ["derive"], default-features = false, optional = true } +arbitrary = { version = "1.3.2", optional = true, features = ["derive"] } [dev-dependencies] hex = "0.4.2" diff --git a/codetable/src/lib.rs b/codetable/src/lib.rs index 940c6864..e9c11a8c 100644 --- a/codetable/src/lib.rs +++ b/codetable/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(feature = "arb", allow(unreachable_code))] // Otherwise the "Cargo Hack" check fails since "arb" includes no hash algos by default #![cfg_attr(docs_rs, feature(doc_cfg))] #![cfg_attr(not(feature = "std"), no_std)] @@ -46,6 +47,7 @@ pub use crate::hasher_impl::strobe::{Strobe256, Strobe512, StrobeHasher}; /// algorithms. See the [`multihash-derive`] crate for more information. /// /// [`multihash-derive`]: https://docs.rs/multihash-derive +#[cfg_attr(feature = "arb", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Copy, Clone, Debug, Eq, MultihashDigest, PartialEq)] #[mh(alloc_size = 64)]