pub struct WordDictionary { /* private fields */ }Expand description
A word-based dictionary for encoding binary data as word sequences.
Unlike character-based Dictionary, this uses whole words as encoding symbols.
Designed for BIP-39, Diceware, PGP word lists, and custom word-based encodings.
§Example
use base_d::WordDictionary;
let dict = WordDictionary::builder()
.words(vec!["abandon", "ability", "able", "about"])
.delimiter(" ")
.build()
.unwrap();
assert_eq!(dict.base(), 4);
assert_eq!(dict.encode_word(0), Some("abandon"));
assert_eq!(dict.decode_word("ability"), Some(1));Implementations§
Source§impl WordDictionary
impl WordDictionary
Sourcepub fn builder() -> WordDictionaryBuilder
pub fn builder() -> WordDictionaryBuilder
Creates a new WordDictionaryBuilder for constructing a WordDictionary.
Sourcepub fn case_sensitive(&self) -> bool
pub fn case_sensitive(&self) -> bool
Returns whether this dictionary uses case-sensitive matching.
Sourcepub fn encode_word(&self, index: usize) -> Option<&str>
pub fn encode_word(&self, index: usize) -> Option<&str>
Encodes a digit (0 to base-1) as a word.
Returns None if the index is out of range.
Sourcepub fn decode_word(&self, word: &str) -> Option<usize>
pub fn decode_word(&self, word: &str) -> Option<usize>
Decodes a word back to its index value.
Returns None if the word is not in the dictionary.
Matching respects the case_sensitive setting.
Trait Implementations§
Source§impl Clone for WordDictionary
impl Clone for WordDictionary
Source§fn clone(&self) -> WordDictionary
fn clone(&self) -> WordDictionary
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WordDictionary
impl RefUnwindSafe for WordDictionary
impl Send for WordDictionary
impl Sync for WordDictionary
impl Unpin for WordDictionary
impl UnwindSafe for WordDictionary
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