#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

#27 in #quickcheck

Download history 279/week @ 2024-07-21 215/week @ 2024-07-28 299/week @ 2024-08-04 176/week @ 2024-08-11 292/week @ 2024-08-18 279/week @ 2024-08-25 456/week @ 2024-09-01 386/week @ 2024-09-08 212/week @ 2024-09-15 427/week @ 2024-09-22 304/week @ 2024-09-29 308/week @ 2024-10-06 363/week @ 2024-10-13 256/week @ 2024-10-20 259/week @ 2024-10-27 191/week @ 2024-11-03

1,081 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

~290–740KB
~17K SLoC