#random #compile-time #macro #parser

get-random-const

简单的编译时随机生成器

6 个稳定版本

2.0.3 2023年4月22日
2.0.2 2023年4月21日
2.0.1 2020年7月17日
1.0.1 2020年4月25日

2135过程宏 中排名

Download history 18/week @ 2024-03-10 1/week @ 2024-03-17 55/week @ 2024-03-31 53/week @ 2024-04-07 58/week @ 2024-04-14 20/week @ 2024-04-21 12/week @ 2024-04-28 19/week @ 2024-05-12 27/week @ 2024-05-19 6/week @ 2024-05-26 50/week @ 2024-06-02 7/week @ 2024-06-09 1/week @ 2024-06-16 13/week @ 2024-06-23

每月下载量 71
xxhash-c 中使用

BSL-1.0 许可证

7KB
93

get-random-const

Crates.io Documentation

编译时生成随机数的宏

use get_random_const::random;

const RANDOM_U8: u8 = random!(u8);
assert_ne!(RANDOM_U8, 0);

static RANDOM_I32: i32 = random!(i32);
assert_ne!(RANDOM_I32, 0);

let random_u32 = random!(u32);
assert_ne!(random_u32, 0);

let random_array = random!([u32;5]);
assert_eq!(random_array.len(), 5);

for elem in random_array.iter() {
    assert_ne!(*elem, 0);
}

let random_array: [u32; 0] = random!([u32;0]); //Well, I guess you can if you want?
assert_eq!(random_array.len(), 0);

lib.rs:

简单的编译时随机生成器

示例

use get_random_const::random;

const RANDOM_U8: u8 = random!(u8);
assert_ne!(RANDOM_U8, 0);

static RANDOM_I32: i32 = random!(i32);
assert_ne!(RANDOM_I32, 0);

assert_ne!(random!(u8), 0u8);
assert_ne!(random!(i8), 0i8);
assert_ne!(random!(u16), 0u16);
assert_ne!(random!(i16), 0i16);
assert_ne!(random!(u32), 0u32);
assert_ne!(random!(i32), 0i32);
assert_ne!(random!(u64), 0u64);
assert_ne!(random!(i64), 0i64);
assert_ne!(random!(u128), 0u128);
assert_ne!(random!(i128), 0i128);
assert_ne!(random!(usize), 0usize);
assert_ne!(random!(isize), 0isize);

let random_array = random!([u32;5]);
assert_eq!(random_array.len(), 5);

for elem in random_array.iter() {
    assert_ne!(*elem, 0);
}

let random_array: [u32; 0] = random!([u32;0]); //Well, I guess you can if you want?
assert_eq!(random_array.len(), 0);

依赖项

~210KB