reth_db_api/
utils.rs
1#[macro_export]
2macro_rules! impl_fixed_arbitrary {
4 ($(($name:ident, $size:expr)),*) => {
5 #[cfg(any(test, feature = "arbitrary"))]
6 use arbitrary::{Arbitrary, Unstructured};
7 $(
8 #[cfg(any(test, feature = "arbitrary"))]
9 impl<'a> Arbitrary<'a> for $name {
10 fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, arbitrary::Error> {
11 let mut buffer = vec![0; $size];
12 u.fill_buffer(buffer.as_mut_slice())?;
13 Decode::decode_owned(buffer).map_err(|_| arbitrary::Error::IncorrectFormat)
14 }
15 }
16
17 #[cfg(any(test, feature = "arbitrary"))]
18 impl proptest::prelude::Arbitrary for $name {
19 type Parameters = ();
20 type Strategy = proptest::strategy::Map<
21 proptest::collection::VecStrategy<<u8 as proptest::arbitrary::Arbitrary>::Strategy>,
22 fn(Vec<u8>) -> Self,
23 >;
24
25 fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
26 use proptest::strategy::Strategy;
27 proptest::collection::vec(proptest::arbitrary::any_with::<u8>(args), $size)
28 .prop_map(move |vec| Decode::decode_owned(vec).unwrap())
29 }
30 }
31 )+
32 };
33}