1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// Derives the trait [`Dice`](./trait.Dice.html) for structs and enums.
///
/// # Limit
///
/// The derived [`Dice`](./trait.Dice.html) implementation will split the [`Limit`](crate::Limit)
/// randomly when generting the fields of `Self`. This helps to limit the overall size of the
/// generated values.
///
/// # Recursion
///
/// Deriving [`Dice`](./trait.Dice.html) for recursive types isn't supported for now.
/// You need to implement it manually.
///
/// ```rust
/// // Recursive types like Foo are not supported!
/// struct Foo {
/// next: Option<Box<Foo>>,
/// }
///
/// // Mutual recursive types like Bar and Baz are also not supported!
/// struct Bar {
/// baz: Baz,
/// }
/// struct Baz {
/// bar: Option<Box<Bar>>,
/// }
/// ```
///
/// # Attributes
///
/// The derived [`Dice`](./trait.Dice.html) implementation can be customized by adding attributes
/// with `#[dice(...)]`.
///
/// ## die
/// The attribute `die` can be used on a field to define the `Die` that is used for
/// this field. It expects an expression that returns a `Die` for the type of the field.
///
/// ```rust
/// use dicetest::prelude::*;
///
/// #[derive(Dice)]
/// struct Foo {
/// name: String,
/// #[dice(die = dice::just(Vec::new()))]
/// _cache: Vec<u8>,
/// }
/// ```
///
/// ## weight
///
/// The attribute `weight` can be used on a variant to define the probability of this variant
/// relative to the other variants. It expects a literal of type `u32`. The default weight of
/// a variant is 1.
///
/// ```rust
/// use dicetest::prelude::*;
///
/// #[derive(Dice)]
/// enum Foo {
/// #[dice(weight = 10)]
/// VeryLikely,
/// #[dice(weight = 5)]
/// Likely,
/// Unlikely,
/// #[dice(weight = 0)]
/// Never,
/// }
/// ```
///
/// # Examples
///
/// ```rust
/// use dicetest::prelude::*;
///
/// #[derive(Dice)]
/// struct Foo(u8);
///
/// #[derive(Dice)]
/// struct Bar {
/// a: String,
/// b: Vec<u8>,
/// }
///
/// #[derive(Dice)]
/// enum FooBar {
/// Foo(Foo),
/// Bar(Bar),
/// }
///
/// #[derive(Dice)]
/// struct Baz<T> {
/// a: Option<T>,
/// b: Vec<T>,
/// }
/// ```
pub use Dice;