//! `rand` on WASI: `random_get`.
use core::mem::MaybeUninit;
use crate::Result;
use crate::sys::cvt;
#[link(wasm_import_module = "wasi_snapshot_preview1")]
unsafe extern "C" {
fn random_get(buf: *mut u8, len: usize) -> i32;
}
pub(crate) fn fill(buf: &mut [MaybeUninit<u8>]) -> Result<()> {
// SAFETY: the host writes exactly `buf.len()` bytes, or fails.
cvt(unsafe { random_get(buf.as_mut_ptr().cast(), buf.len()) })
}