1 个不稳定版本
0.1.0 | 2022 年 4 月 21 日 |
---|
#2983 in Rust 模式
134 每月下载次数
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