mnemonic_external/
regular.rs1#[cfg(not(feature = "std"))]
2use alloc::vec::Vec;
3
4#[cfg(feature = "std")]
5use std::vec::Vec;
6
7use crate::error::ErrorMnemonic;
8use crate::wordlist::WORDLIST_ENGLISH;
9use crate::{AsWordList, Bits11, WordListElement};
10
11pub struct InternalWordList;
12
13impl AsWordList for InternalWordList {
14 type Word = &'static str;
15
16 fn get_word(&self, bits: Bits11) -> Result<Self::Word, ErrorMnemonic> {
17 let word_order = bits.bits() as usize;
18 Ok(WORDLIST_ENGLISH[word_order])
19 }
20
21 fn get_words_by_prefix(
22 &self,
23 prefix: &str,
24 ) -> Result<Vec<WordListElement<Self>>, ErrorMnemonic> {
25 let mut out: Vec<WordListElement<Self>> = Vec::new();
26 for (i, word) in WORDLIST_ENGLISH.iter().enumerate() {
27 if word.starts_with(prefix) {
28 out.push(WordListElement {
29 word,
30 bits11: Bits11::from(i as u16)?,
31 })
32 }
33 }
34 Ok(out)
35 }
36
37 fn bits11_for_word(&self, word: &str) -> Result<Bits11, ErrorMnemonic> {
38 for (i, element) in WORDLIST_ENGLISH.iter().enumerate() {
39 if element == &word {
40 return Bits11::from(i as u16);
41 }
42 }
43 Err(ErrorMnemonic::NoWord)
44 }
45}