#quickcheck #value #default #skip #10-000

macro derive-quickcheck-arbitrary

derive quickcheck::Arbitrary

4 releases

0.1.3 Sep 13, 2023
0.1.2 Aug 25, 2023
0.1.1 Jul 31, 2023
0.1.0 Jul 31, 2023

#33 in #quickcheck

Download history 24/week @ 2024-12-25 185/week @ 2025-01-01 280/week @ 2025-01-08 275/week @ 2025-01-15 226/week @ 2025-01-22 262/week @ 2025-01-29 596/week @ 2025-02-05 631/week @ 2025-02-12 399/week @ 2025-02-19 326/week @ 2025-02-26 380/week @ 2025-03-05 477/week @ 2025-03-12 389/week @ 2025-03-19 321/week @ 2025-03-26 448/week @ 2025-04-02 380/week @ 2025-04-09

1,687 downloads per month
Used in 4 crates

MIT license

17KB
359 lines

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,
}

Dependencies

~260–700KB
~16K SLoC