#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

#1560 in Procedural macros

Download history 30/week @ 2023-12-15 10/week @ 2023-12-22 224/week @ 2023-12-29 178/week @ 2024-01-05 230/week @ 2024-01-12 323/week @ 2024-01-19 316/week @ 2024-01-26 243/week @ 2024-02-02 92/week @ 2024-02-09 283/week @ 2024-02-16 371/week @ 2024-02-23 484/week @ 2024-03-01 266/week @ 2024-03-08 464/week @ 2024-03-15 442/week @ 2024-03-22 147/week @ 2024-03-29

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