pub struct Alphabet { /* private fields */ }Expand description
Represents an encoding alphabet with its characters and configuration.
An alphabet defines the character set and encoding mode used for converting binary data to text. Supports three modes: mathematical base conversion, chunked (RFC 4648), and byte-range mapping.
Implementations§
Source§impl Alphabet
impl Alphabet
Sourcepub fn new_with_mode(
chars: Vec<char>,
mode: EncodingMode,
padding: Option<char>,
) -> Result<Self, String>
pub fn new_with_mode( chars: Vec<char>, mode: EncodingMode, padding: Option<char>, ) -> Result<Self, String>
Creates a new alphabet with specified encoding mode and optional padding.
§Arguments
chars- Vector of characters to use in the alphabetmode- Encoding mode (BaseConversion, Chunked, or ByteRange)padding- Optional padding character (typically ‘=’ for RFC modes)
§Errors
Returns an error if:
- The alphabet is empty or contains duplicates
- Chunked mode is used with a non-power-of-two alphabet size
Sourcepub fn new_with_mode_and_range(
chars: Vec<char>,
mode: EncodingMode,
padding: Option<char>,
start_codepoint: Option<u32>,
) -> Result<Self, String>
pub fn new_with_mode_and_range( chars: Vec<char>, mode: EncodingMode, padding: Option<char>, start_codepoint: Option<u32>, ) -> Result<Self, String>
Creates a new alphabet with full configuration including byte-range support.
§Arguments
chars- Vector of characters (empty for ByteRange mode)mode- Encoding modepadding- Optional padding characterstart_codepoint- Starting Unicode codepoint for ByteRange mode
§Errors
Returns an error if configuration is invalid for the specified mode.
Sourcepub fn from_str(s: &str) -> Result<Self, String>
pub fn from_str(s: &str) -> Result<Self, String>
Creates an alphabet from a string of characters.
§Arguments
s- String containing the alphabet characters
Sourcepub fn base(&self) -> usize
pub fn base(&self) -> usize
Returns the base (radix) of the alphabet.
For ByteRange mode, always returns 256. Otherwise returns the number of characters.
Sourcepub fn mode(&self) -> &EncodingMode
pub fn mode(&self) -> &EncodingMode
Returns the encoding mode of this alphabet.
Sourcepub fn start_codepoint(&self) -> Option<u32>
pub fn start_codepoint(&self) -> Option<u32>
Returns the starting Unicode codepoint for ByteRange mode.
Sourcepub fn encode_digit(&self, digit: usize) -> Option<char>
pub fn encode_digit(&self, digit: usize) -> Option<char>
Encodes a digit (0 to base-1) as a character.
Returns None if the digit is out of range.
Sourcepub fn decode_char(&self, c: char) -> Option<usize>
pub fn decode_char(&self, c: char) -> Option<usize>
Decodes a character back to its digit value.
Returns None if the character is not in the alphabet.