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
+6 -3
View File
@@ -14,13 +14,16 @@ fn main() -> std::io::Result<()> {
println!("offset : {}", rng.gen_range_i32_in(-10..=10)?);
println!("index : {}", rng.gen_range_usize_in(0..16)?);
let token = rng.string_from(charset::ALPHANUMERIC, 24)?;
let token = rng.token(24)?;
println!("token : {token}");
let hex = rng.string_from(charset::HEX_LOWER, 32)?;
let hex = rng.hex(32)?;
println!("hex : {hex}");
let pin = rng.string_from(charset::DIGITS, 6)?;
let custom = rng.string_from(charset::ALPHANUMERIC, 12)?;
println!("custom : {custom}");
let pin = rng.pin(6)?;
println!("pin : {pin}");
Ok(())