derive-quickcheck-arbitrary

Crates.ioderive-quickcheck-arbitrary
lib.rsderive-quickcheck-arbitrary
version0.1.3
sourcesrc
created_at2023-07-31 12:24:27.049434
updated_at2023-09-13 11:00:22.438505
descriptionderive quickcheck::Arbitrary
homepage
repositoryhttps://github.com/aatifsyed/derive-quickcheck-arbitrary
max_upload_size
id930814
size18,936
Aatif Syed (aatifsyed)

documentation

https://docs.rs/derive-quickcheck-arbitrary

README

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:

#[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,
}
Commit count: 22

cargo fmt