1 unstable release

0.1.0 Apr 21, 2022

#2983 in Rust patterns

Download history 18/week @ 2024-04-15 34/week @ 2024-04-29 9/week @ 2024-05-06 21/week @ 2024-05-13 9/week @ 2024-05-20 59/week @ 2024-05-27 95/week @ 2024-06-03 52/week @ 2024-06-10 49/week @ 2024-06-17 26/week @ 2024-06-24 19/week @ 2024-07-01 36/week @ 2024-07-08 37/week @ 2024-07-15 32/week @ 2024-07-22

134 downloads per month

MIT/Apache

6KB
94 lines

Generate-Random

Generate random data.

Example

use generate_random::GenerateRandom;

#[derive(GenerateRandom)]
enum MyEnum {
    A,
    C(bool),
    B {
        x: u8,
    },
    // Providing a weight allows changing the probabilities.
    // This variant is now twice as likely to be generated as the others.
    #[weight(2)]
    D,
}

let mut rng = rand::thread_rng();
let my_value = MyEnum::generate_random(&mut rng);

Documentation

Documentation


lib.rs:

Generate random data.

Examples

use generate_random::GenerateRandom;

#[derive(GenerateRandom)]
enum MyEnum {
    A,
    C(bool),
    B {
        x: u8,
    },
    // Providing a weight allows changing the probabilities.
    // This variant is now twice as likely to be generated as the others.
    #[weight(2)]
    D,
}

let mut rng = rand::thread_rng();
let my_value = MyEnum::generate_random(&mut rng);

Dependencies

~2MB
~40K SLoC