DictionaryRegistry

Struct DictionaryRegistry 

Source
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: Settings

Global settings

Implementations§

Source§

impl DictionaryRegistry

Source

pub fn from_toml(content: &str) -> Result<Self, Error>

Parses dictionary configurations from TOML content.

Source

pub fn load_default() -> Result<Self, Box<dyn Error>>

Loads the built-in dictionary configurations.

Returns the default dictionaries bundled with the library.

Source

pub fn load_from_file(path: &Path) -> Result<Self, Box<dyn Error>>

Loads configuration from a custom file path.

Source

pub fn load_with_overrides() -> Result<Self, Box<dyn Error>>

Loads configuration with user overrides from standard locations.

Searches in priority order:

  1. Built-in dictionaries (from library)
  2. ~/.config/base-d/dictionaries.toml (user overrides)
  3. ./dictionaries.toml (project-local overrides)

Later configurations override earlier ones for matching dictionary names.

Source

pub fn merge(&mut self, other: DictionaryRegistry)

Merges another configuration into this one.

Dictionaries from other override dictionaries with the same name in self.

Source

pub fn get_dictionary(&self, name: &str) -> Option<&DictionaryConfig>

Retrieves an dictionary configuration by name.

Source

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:

  1. Looking up the dictionary config
  2. Getting effective chars
  3. 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);
Source

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);
Source

pub fn names(&self) -> Vec<&str>

Returns a list of all dictionary names.

Source

pub fn common_names(&self) -> Vec<&str>

Returns a list of common dictionary names (suitable for random selection).

Source

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")?;
Source

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")?;
Source

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.

Source

pub fn is_word_dictionary(&self, name: &str) -> bool

Checks if a dictionary is word-based.

Trait Implementations§

Source§

impl Debug for DictionaryRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DictionaryRegistry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,