Files
ez-urandom/examples/bytes.rs
T
ddidderr 733a2508cb feat: add byte-fill convenience construction
Add OsRandom::fill_bytes so callers can fill a byte slice without importing
std::io::Read. This keeps the common raw-byte use case close to the rest of
the crate's typed convenience API while still forwarding to the same
/dev/urandom handle.

Implement Default for OsRandom as the infallible convenience constructor. The
fallible OsRandom::try_new API remains the right choice when the caller wants
to handle an unavailable operating-system randomness source explicitly.

Document the public constructors and byte-fill helper with working examples,
and add a runnable bytes example for the top-level workflow.

Test Plan:
- cargo test
- cargo clippy
- cargo clippy --benches
- cargo clippy --tests
- cargo +nightly fmt

Refs: IDEAS.md ergonomics backlog
2026-04-28 19:58:27 +02:00

15 lines
291 B
Rust

//! Run with: `cargo run --example bytes`
use ez_urandom::OsRandom;
fn main() -> std::io::Result<()> {
let mut rng = OsRandom::default();
let mut session_key = [0u8; 32];
rng.fill_bytes(&mut session_key)?;
println!("session key bytes: {session_key:02x?}");
Ok(())
}