pub struct Alphabet { /* private fields */ }Expand description
A validated set of ASCII code symbols.
Implementations§
Source§impl Alphabet
impl Alphabet
Sourcepub fn new(symbols: &[u8]) -> Result<Self, PolicyError>
pub fn new(symbols: &[u8]) -> Result<Self, PolicyError>
Build an alphabet from raw bytes, validating the invariants required for unbiased generation (RFC-003 §11.1):
- at least 2 symbols,
- all symbols ASCII,
- no duplicate symbols.
§Errors
Returns PolicyError if any invariant is violated.
Sourcepub fn unambiguous() -> Self
pub fn unambiguous() -> Self
The unambiguous default alphabet (31 symbols).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the alphabet is empty. Always false for a constructed
alphabet, present to satisfy clippy and API completeness.
Sourcepub fn unbiased_ceiling(&self) -> usize
pub fn unbiased_ceiling(&self) -> usize
The rejection-sampling ceiling: the largest multiple of the alphabet
length that fits in a byte. Random bytes >= ceiling are discarded to
avoid modulo bias (RFC-003 §4, §11.5). For the 31-symbol default this is
256 - (256 % 31) = 248.
Trait Implementations§
impl Eq for Alphabet
impl StructuralPartialEq for Alphabet
Auto Trait Implementations§
impl Freeze for Alphabet
impl RefUnwindSafe for Alphabet
impl Send for Alphabet
impl Sync for Alphabet
impl Unpin for Alphabet
impl UnsafeUnpin for Alphabet
impl UnwindSafe for Alphabet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more