Expand description
Derive macro for quickcheck::Arbitrary
.
Expands to calling Arbitrary::arbitrary
on every field of a struct.
use derive_quickcheck_arbitrary::Arbitrary;
#[derive(Clone, Arbitrary)]
struct Yakshaver {
id: usize,
name: String,
}
You can customise field generation by either:
- providing a callable that accepts
&mut quickcheck::Gen
. - always using the default value
#[derive(Clone, Arbitrary)]
struct Yakshaver {
/// Must be less than 10_000
#[arbitrary(gen(|g| num::clamp(usize::arbitrary(g), 0, 10_000) ))]
id: usize,
name: String,
#[arbitrary(default)]
always_false: bool,
}
You can skip enum variants:
#[derive(Clone, Arbitrary)]
enum YakType {
Domestic {
name: String,
},
Wild,
#[arbitrary(skip)]
Alien,
}
You can add bounds for generic structs:
#[derive(Clone, Arbitrary)]
#[arbitrary(where(T: Arbitrary))]
struct GenericYak<T> {
name: T,
}