#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

#1577 in Procedural macros

Download history 167/week @ 2024-01-10 304/week @ 2024-01-17 378/week @ 2024-01-24 270/week @ 2024-01-31 80/week @ 2024-02-07 248/week @ 2024-02-14 293/week @ 2024-02-21 424/week @ 2024-02-28 365/week @ 2024-03-06 444/week @ 2024-03-13 455/week @ 2024-03-20 229/week @ 2024-03-27 394/week @ 2024-04-03 582/week @ 2024-04-10 638/week @ 2024-04-17 146/week @ 2024-04-24

1,823 downloads per month
Used in 2 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

~0.4–0.8MB
~19K SLoC