1 个不稳定版本

0.1.0 2022 年 4 月 21 日

#2983 in Rust 模式

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

134 每月下载次数

MIT/Apache

6KB
94

Generate-Random

生成随机数据。

示例

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);

文档

文档


lib.rs:

生成随机数据。

示例

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);

依赖

~2MB
~40K SLoC