pub struct DictionaryRegistry {
pub dictionaries: HashMap<String, DictionaryConfig>,
pub compression: HashMap<String, CompressionConfig>,
pub settings: Settings,
}Expand description
Collection of dictionary configurations loaded from TOML files.
Fields§
§dictionaries: HashMap<String, DictionaryConfig>Map of dictionary names to their configurations
compression: HashMap<String, CompressionConfig>Compression algorithm configurations
settings: SettingsGlobal settings
Implementations§
Source§impl DictionaryRegistry
impl DictionaryRegistry
Sourcepub fn from_toml(content: &str) -> Result<Self, Error>
pub fn from_toml(content: &str) -> Result<Self, Error>
Parses dictionary configurations from TOML content.
Sourcepub fn load_default() -> Result<Self, Box<dyn Error>>
pub fn load_default() -> Result<Self, Box<dyn Error>>
Loads the built-in dictionary configurations.
Returns the default dictionaries bundled with the library.
Sourcepub fn load_from_file(path: &Path) -> Result<Self, Box<dyn Error>>
pub fn load_from_file(path: &Path) -> Result<Self, Box<dyn Error>>
Loads configuration from a custom file path.
Sourcepub fn load_with_overrides() -> Result<Self, Box<dyn Error>>
pub fn load_with_overrides() -> Result<Self, Box<dyn Error>>
Loads configuration with user overrides from standard locations.
Searches in priority order:
- Built-in dictionaries (from library)
~/.config/base-d/dictionaries.toml(user overrides)./dictionaries.toml(project-local overrides)
Later configurations override earlier ones for matching dictionary names.
Sourcepub fn merge(&mut self, other: DictionaryRegistry)
pub fn merge(&mut self, other: DictionaryRegistry)
Merges another configuration into this one.
Dictionaries from other override dictionaries with the same name in self.
Sourcepub fn get_dictionary(&self, name: &str) -> Option<&DictionaryConfig>
pub fn get_dictionary(&self, name: &str) -> Option<&DictionaryConfig>
Retrieves an dictionary configuration by name.
Sourcepub fn dictionary(
&self,
name: &str,
) -> Result<Dictionary, DictionaryNotFoundError>
pub fn dictionary( &self, name: &str, ) -> Result<Dictionary, DictionaryNotFoundError>
Builds a ready-to-use Dictionary from a named configuration.
This is a convenience method that handles the common pattern of:
- Looking up the dictionary config
- Getting effective chars
- Building the Dictionary with proper mode/padding
§Example
let registry = DictionaryRegistry::load_default()?;
let dict = registry.dictionary("base64")?;
let encoded = base_d::encode(b"Hello", &dict);Sourcepub fn random(&self) -> Result<(String, Dictionary), Box<dyn Error>>
pub fn random(&self) -> Result<(String, Dictionary), Box<dyn Error>>
Returns a random dictionary suitable for encoding.
Only selects from dictionaries marked as common = true (the default).
These are dictionaries that render consistently across platforms.
§Example
let registry = DictionaryRegistry::load_default()?;
let (name, dict) = registry.random()?;
let encoded = base_d::encode(b"Hello", &dict);Sourcepub fn common_names(&self) -> Vec<&str>
pub fn common_names(&self) -> Vec<&str>
Returns a list of common dictionary names (suitable for random selection).
Sourcepub fn word_dictionary(
&self,
name: &str,
) -> Result<WordDictionary, DictionaryNotFoundError>
pub fn word_dictionary( &self, name: &str, ) -> Result<WordDictionary, DictionaryNotFoundError>
Builds a WordDictionary from a named configuration.
§Errors
Returns error if:
- Dictionary not found
- Dictionary is not word-type
- Word list file cannot be read
- Word dictionary building fails
§Example
let registry = DictionaryRegistry::load_default()?;
// Would work if bip39 is defined as a word dictionary
// let dict = registry.word_dictionary("bip39")?;Sourcepub fn alternating_word_dictionary(
&self,
name: &str,
) -> Result<AlternatingWordDictionary, DictionaryNotFoundError>
pub fn alternating_word_dictionary( &self, name: &str, ) -> Result<AlternatingWordDictionary, DictionaryNotFoundError>
Builds an AlternatingWordDictionary from a named configuration.
This is used for PGP-style biometric word lists where even/odd bytes use different dictionaries.
§Errors
Returns error if:
- Dictionary not found
- Dictionary is not word-type
- Dictionary does not have alternating field set
- Any of the sub-dictionaries cannot be loaded
§Example
let registry = DictionaryRegistry::load_default()?;
let dict = registry.alternating_word_dictionary("pgp")?;Sourcepub fn dictionary_type(&self, name: &str) -> Option<DictionaryType>
pub fn dictionary_type(&self, name: &str) -> Option<DictionaryType>
Returns the dictionary type for a named dictionary.
Returns None if the dictionary is not found.
Sourcepub fn is_word_dictionary(&self, name: &str) -> bool
pub fn is_word_dictionary(&self, name: &str) -> bool
Checks if a dictionary is word-based.