pub struct Dictionary { /* private fields */ }Expand description
Represents an encoding dictionary with its characters and configuration.
An dictionary 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 Dictionary
impl Dictionary
Sourcepub fn builder() -> DictionaryBuilder
pub fn builder() -> DictionaryBuilder
Creates a new DictionaryBuilder for constructing a Dictionary.
§Example
use base_d::{Dictionary, EncodingMode};
let dict = Dictionary::builder()
.chars_from_str("0123456789ABCDEF")
.mode(EncodingMode::Radix)
.build()
.unwrap();Sourcepub fn new(chars: Vec<char>) -> Result<Self, String>
👎Deprecated since 0.1.0: Use Dictionary::builder() instead
pub fn new(chars: Vec<char>) -> Result<Self, String>
Creates a new dictionary with default settings (Radix mode, no padding).
§Arguments
chars- Vector of characters to use in the dictionary
§Errors
Returns an error if the dictionary is empty or contains duplicate characters.
§Deprecated
Use Dictionary::builder() instead for more flexible configuration.
Sourcepub fn new_with_mode(
chars: Vec<char>,
mode: EncodingMode,
padding: Option<char>,
) -> Result<Self, String>
👎Deprecated since 0.1.0: Use Dictionary::builder() instead
pub fn new_with_mode( chars: Vec<char>, mode: EncodingMode, padding: Option<char>, ) -> Result<Self, String>
Creates a new dictionary with specified encoding mode and optional padding.
§Arguments
chars- Vector of characters to use in the dictionarymode- Encoding mode (Radix, Chunked, or ByteRange)padding- Optional padding character (typically ‘=’ for RFC modes)
§Errors
Returns an error if:
- The dictionary is empty or contains duplicates
- Chunked mode is used with a non-power-of-two dictionary size
§Deprecated
Use Dictionary::builder() instead for more flexible configuration.
Sourcepub fn new_with_mode_and_range(
chars: Vec<char>,
mode: EncodingMode,
padding: Option<char>,
start_codepoint: Option<u32>,
) -> Result<Self, String>
👎Deprecated since 0.1.0: Use Dictionary::builder() instead
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 dictionary 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.
§Deprecated
Use Dictionary::builder() instead for more flexible configuration.
Sourcepub fn from_str(s: &str) -> Result<Self, String>
👎Deprecated since 0.1.0: Use Dictionary::builder().chars_from_str(s).build() instead
pub fn from_str(s: &str) -> Result<Self, String>
Sourcepub fn base(&self) -> usize
pub fn base(&self) -> usize
Returns the base (radix) of the dictionary.
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 dictionary.
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 dictionary.
Sourcepub fn simd_metadata(&self) -> DictionaryMetadata
pub fn simd_metadata(&self) -> DictionaryMetadata
Returns SIMD metadata for this dictionary.
This provides information about whether SIMD acceleration is available for this dictionary and which implementation to use.
Sourcepub fn simd_available(&self) -> bool
pub fn simd_available(&self) -> bool
Returns whether SIMD acceleration is available for this dictionary.
This is a convenience method that checks if SIMD can be used with the current CPU features and dictionary configuration.
Trait Implementations§
Source§impl Clone for Dictionary
impl Clone for Dictionary
Source§fn clone(&self) -> Dictionary
fn clone(&self) -> Dictionary
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more