impl feature gated quickcheck arbitrary for hash
This commit is contained in:
parent
59c05a4450
commit
7e3a4fb4aa
|
@ -11,8 +11,10 @@ heapsize = { version = "0.4", optional = true }
|
|||
libc = { version = "0.2", optional = true, default-features = false }
|
||||
rand = { version = "0.4", optional = true }
|
||||
rustc-hex = { version = "1.0", optional = true }
|
||||
quickcheck = { version = "0.6", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["libc"]
|
||||
std = ["rustc-hex", "rand"]
|
||||
heapsizeof = ["heapsize"]
|
||||
impl_quickcheck_arbitrary = ["quickcheck"]
|
||||
|
|
23
src/hash.rs
23
src/hash.rs
|
@ -301,6 +301,7 @@ macro_rules! construct_hash {
|
|||
impl_std_for_hash!($from, $size);
|
||||
impl_heapsize_for_hash!($from);
|
||||
impl_libc_for_hash!($from, $size);
|
||||
impl_quickcheck_arbitrary_for_hash!($from, $size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,3 +464,25 @@ macro_rules! impl_libc_for_hash {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="impl_quickcheck_arbitrary")]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! impl_quickcheck_arbitrary_for_hash {
|
||||
($name: ty, $n_bytes: tt) => {
|
||||
impl $crate::quickcheck::Arbitrary for $name {
|
||||
fn arbitrary<G: $crate::quickcheck::Gen>(g: &mut G) -> Self {
|
||||
let mut res = [0u8; $n_bytes];
|
||||
g.fill_bytes(&mut res[..$n_bytes]);
|
||||
res.as_ref().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature="impl_quickcheck_arbitrary"))]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! impl_quickcheck_arbitrary_for_hash {
|
||||
($name: ty, $n_bytes: tt) => {}
|
||||
}
|
||||
|
|
|
@ -32,5 +32,9 @@ pub extern crate rustc_hex;
|
|||
#[doc(hidden)]
|
||||
pub extern crate rand;
|
||||
|
||||
#[cfg(feature="impl_quickcheck_arbitrary")]
|
||||
#[doc(hidden)]
|
||||
pub extern crate quickcheck;
|
||||
|
||||
mod hash;
|
||||
pub use hash::*;
|
||||
|
|
Loading…
Reference in New Issue