6 stable releases
2.0.3 | Apr 22, 2023 |
---|---|
2.0.2 | Apr 21, 2023 |
2.0.1 | Jul 17, 2020 |
1.0.1 | Apr 25, 2020 |
#2372 in Procedural macros
66 downloads per month
Used in xxhash-c
7KB
93 lines
get-random-const
Macro to generate random at compile time
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
:
Simple compile time random generator
Example
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);
Dependencies
~215KB