| 1 |
use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#; |
| 2 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!; |
| 3 |
|
| 4 |
use once_cellrust-analyzer cargo once_cell 1.21.4 crate/::racerust-analyzer cargo once_cell 1.21.4 race/::OnceBoxrust-analyzer cargo once_cell 1.21.4 race/once_box/OnceBox#; |
| •5 |
use tiny_keccakrust-analyzer cargo tiny-keccak 2.0.2 crate/::{Hasherrust-analyzer cargo tiny-keccak 2.0.2 Hasher#, Shakerust-analyzer cargo tiny-keccak 2.0.2 shake/Shake#, Xofrust-analyzer cargo tiny-keccak 2.0.2 Xof#}; |
| 6 |
|
| 7 |
static SEEDrust-analyzer cargo const-random-macro 0.1.16 span/SEED.: OnceBoxrust-analyzer cargo once_cell 1.21.4 race/once_box/OnceBox#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> = OnceBoxrust-analyzer cargo once_cell 1.21.4 race/once_box/OnceBox#::newrust-analyzer cargo once_cell 1.21.4 race/once_box/impl#[`OnceBox<T>`]new().(); |
| 8 |
|
| 9 |
fn get_seedrust-analyzer cargo const-random-macro 0.1.16 span/get_seed().() -> &'static [u8] { |
| 10 |
&SEEDrust-analyzer cargo const-random-macro 0.1.16 span/SEED..get_or_initrust-analyzer cargo once_cell 1.21.4 race/once_box/impl#[`OnceBox<T>`]get_or_init().(|| { |
| 11 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("CONST_RANDOM_SEED") { |
| •12 |
Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(value.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 13 |
} else { |
| 14 |
let mut value = [0u8; 32]; |
| •15 |
getrandomrust-analyzer cargo getrandom 0.4.3 crate/::fillrust-analyzer cargo getrandom 0.4.3 fill().(&mut value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 16 |
Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(value.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 17 |
} |
| 18 |
})[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 19 |
} |
| 20 |
|
| 21 |
pub(craterust-analyzer cargo const-random-macro 0.1.16 crate/) fn gen_randomrust-analyzer cargo const-random-macro 0.1.16 span/gen_random().<T: Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random#>() -> T { |
| 22 |
Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random#::randomrust-analyzer cargo const-random-macro 0.1.16 span/Random#random().() |
| 23 |
} |
| 24 |
|
| 25 |
pub(craterust-analyzer cargo const-random-macro 0.1.16 crate/) fn gen_random_bytesrust-analyzer cargo const-random-macro 0.1.16 span/gen_random_bytes().(output: &mut [u8]) { |
| 26 |
hash_stuffrust-analyzer cargo const-random-macro 0.1.16 span/hash_stuff().().squeezerust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake][Xof]squeeze().(output) |
| 27 |
} |
| 28 |
|
| 29 |
pub(craterust-analyzer cargo const-random-macro 0.1.16 crate/) trait Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# { |
| 30 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/Random#random().() -> Self; |
| 31 |
} |
| 32 |
|
| 33 |
fn hash_stuffrust-analyzer cargo const-random-macro 0.1.16 span/hash_stuff().() -> impl Xofrust-analyzer cargo tiny-keccak 2.0.2 Xof# { |
| 34 |
let span = Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#::call_siterust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Span]call_site().(); |
| 35 |
let mut hasher = Shakerust-analyzer cargo tiny-keccak 2.0.2 shake/Shake#::v256rust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake]v256().(); |
| 36 |
hasher.updaterust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake][Hasher]update().(get_seedrust-analyzer cargo const-random-macro 0.1.16 span/get_seed().()); |
| 37 |
hasher.updaterust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake][Hasher]update().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", span).as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()); |
| 38 |
hasher |
| 39 |
} |
| 40 |
|
| 41 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for u64 { |
| 42 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random] { |
| 43 |
let mut output = [0; 8]; |
| 44 |
hash_stuffrust-analyzer cargo const-random-macro 0.1.16 span/hash_stuff().().squeezerust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake][Xof]squeeze().(&mut output); |
| 45 |
Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]::from_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_ne_bytes().(output) |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for u128 { |
| 50 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u128][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u128][Random] { |
| 51 |
let mut output = [0; 16]; |
| 52 |
hash_stuffrust-analyzer cargo const-random-macro 0.1.16 span/hash_stuff().().squeezerust-analyzer cargo tiny-keccak 2.0.2 shake/impl#[Shake][Xof]squeeze().(&mut output); |
| 53 |
Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u128][Random]::from_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u128]from_ne_bytes().(output) |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for u8 { |
| 58 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u8][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u8][Random] { |
| 59 |
u64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]random().() as u8 |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for u16 { |
| 64 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u16][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u16][Random] { |
| 65 |
u64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]random().() as u16 |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for u32 { |
| 70 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u32][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u32][Random] { |
| 71 |
u64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]random().() as u32 |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for i8 { |
| 76 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i8][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i8][Random] { |
| 77 |
i64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i64][Random]random().() as i8 |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for i16 { |
| 82 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i16][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i16][Random] { |
| 83 |
i64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i64][Random]random().() as i16 |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for i32 { |
| 88 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i32][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i32][Random] { |
| 89 |
i64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i64][Random]random().() as i32 |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for i64 { |
| 94 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i64][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i64][Random] { |
| 95 |
u64::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u64][Random]random().() as i64 |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
impl Randomrust-analyzer cargo const-random-macro 0.1.16 span/Random# for i128 { |
| 100 |
fn randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i128][Random]random().() -> Selfrust-analyzer cargo const-random-macro 0.1.16 span/impl#[i128][Random] { |
| 101 |
u128::randomrust-analyzer cargo const-random-macro 0.1.16 span/impl#[u128][Random]random().() as i128 |
| 102 |
} |
| 103 |
} |