d618bd7cc9
Capture a short backlog of ergonomy improvements for the public API so the ideas don't get lost between sessions. This is a planning document only — no code changes, and nothing here is committed to as a roadmap. Items recorded: - Thread-local global helpers (e.g. `random_u64()`) to avoid threading an `OsRandom` through call sites for one-off uses. - `gen_range` for all integer widths and `Range`/`RangeInclusive` overloads; today only `gen_range_u32` exists. - `fill_bytes(&mut [u8])` so callers don't need to bring `io::Read` into scope just to fill a buffer. - `bool()` and `f64()` (unit interval) helpers. - Generic `shuffle(&mut [T])` and `choose<T>(&[T]) -> &T`, not just byte slices. - Accept `&str` alphabets directly and drop the ASCII assert by iterating `chars()` instead of bytes. - Loosen `&mut self` to `&self` (interior buffering) or impl `Clone`, so multiple call sites can share a handle without borrow-checker friction. - Preset constructors: `OsRandom::password(len)`, `::hex(len)`, `::token(len)`.
759 B
759 B
Ergonomy ideas
Default/thread_localglobal:ez_urandom::random_u64()without constructing or threading anOsRandom.gen_rangefor all int widths (currently onlyu32) plus aRange/RangeInclusiveoverload.fill_bytes(&mut [u8])convenience so callers don't need to importio::Read.bool()/f64()(unit interval) helpers.shuffle(&mut [T])andchoose<T>(&[T]) -> &T— generic, not just bytes.- Accept a
&stralphabet directly (not just&[u8]) and drop the ASCII assert by iteratingchars(). - Loosen
&mut selfto&selfvia interior buffering, or implClone, so multiple call sites don't fight the borrow checker. - Builder / presets:
OsRandom::password(len),::hex(len),::token(len).