feat: add common string presets

Add token, hex, and pin helpers for the common ASCII string formats already
represented by the crate's built-in charsets. These methods keep frequent use
cases concise while continuing to route through string_from, so callers still
get the same uniform per-character sampling behavior.

Avoid adding a password preset in this change. Password generation implies
policy choices around symbols, ambiguous characters, and service-specific
constraints, while these presets are direct names for existing alphabets.

Document every preset with doctested examples and add a runnable presets
example. Update the demo to show both presets and custom string generation.

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

Refs: IDEAS.md ergonomics backlog
This commit is contained in:
2026-04-28 20:06:39 +02:00
parent 0365ab86d1
commit 53fc84a270
3 changed files with 93 additions and 3 deletions
+17
View File
@@ -0,0 +1,17 @@
//! Run with: `cargo run --example presets`
use ez_urandom::OsRandom;
fn main() -> std::io::Result<()> {
let mut rng = OsRandom::try_new()?;
let token = rng.token(24)?;
let hex = rng.hex(32)?;
let pin = rng.pin(6)?;
println!("token: {token}");
println!("hex : {hex}");
println!("pin : {pin}");
Ok(())
}