#quickcheck #derive #field #gen #macro #clone #enums

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

#30 in #quickcheck

Download history 296/week @ 2024-05-13 186/week @ 2024-05-20 139/week @ 2024-05-27 362/week @ 2024-06-03 247/week @ 2024-06-10 332/week @ 2024-06-17 211/week @ 2024-06-24 440/week @ 2024-07-01 360/week @ 2024-07-08 554/week @ 2024-07-15 279/week @ 2024-07-22 213/week @ 2024-07-29 304/week @ 2024-08-05 171/week @ 2024-08-12 293/week @ 2024-08-19 275/week @ 2024-08-26

1,049 downloads per month
Used in 3 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

~315–770KB
~18K SLoC