diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ba688..3332446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ CHANGELOG ========= +# v2.1.0 + +- Add support for Portuguese as per addition to BIP. +- Add constant Language::ALL and deprecate Language::all() +- Add Mnemonic::words and deprecate Mnemonic::word_iter +- Add Mnemonic::word_indices +- Use `rand_core` if `rand` feature is not set +- Add `alloc` feature to gate `unicode-normalization` + # v2.0.0 - Set Rust edition to 2018 diff --git a/Cargo.toml b/Cargo.toml index 8c5b1da..cc521ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bip39" -version = "2.0.0" +version = "2.1.0" authors = ["Steven Roose "] license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-bip39/" diff --git a/src/language/mod.rs b/src/language/mod.rs index 6aabb33..99da0de 100644 --- a/src/language/mod.rs +++ b/src/language/mod.rs @@ -69,28 +69,33 @@ impl Default for Language { impl Language { /// The list of supported languages. /// Language support is managed by compile features. + pub const ALL: &'static [Language] = &[ + Language::English, + #[cfg(feature = "chinese-simplified")] + Language::SimplifiedChinese, + #[cfg(feature = "chinese-traditional")] + Language::TraditionalChinese, + #[cfg(feature = "czech")] + Language::Czech, + #[cfg(feature = "french")] + Language::French, + #[cfg(feature = "italian")] + Language::Italian, + #[cfg(feature = "japanese")] + Language::Japanese, + #[cfg(feature = "korean")] + Language::Korean, + #[cfg(feature = "portuguese")] + Language::Portuguese, + #[cfg(feature = "spanish")] + Language::Spanish, + ]; + + /// The list of supported languages. + /// Language support is managed by compile features. + #[deprecated(since = "2.1.0", note = "use constant Language::ALL instead")] pub fn all() -> &'static [Language] { - &[ - Language::English, - #[cfg(feature = "chinese-simplified")] - Language::SimplifiedChinese, - #[cfg(feature = "chinese-traditional")] - Language::TraditionalChinese, - #[cfg(feature = "czech")] - Language::Czech, - #[cfg(feature = "french")] - Language::French, - #[cfg(feature = "italian")] - Language::Italian, - #[cfg(feature = "japanese")] - Language::Japanese, - #[cfg(feature = "korean")] - Language::Korean, - #[cfg(feature = "portuguese")] - Language::Portuguese, - #[cfg(feature = "spanish")] - Language::Spanish, - ] + Language::ALL } /// The word list for this language. @@ -306,7 +311,7 @@ mod tests { // Afterwards, we make sure that no word maps to multiple languages // if either of those is guaranteed to have unique words. let mut words: HashMap<&str, Vec> = HashMap::new(); - for lang in Language::all().iter() { + for lang in Language::ALL.iter() { for word in lang.word_list().iter() { words.entry(word).or_insert(Vec::new()).push(*lang); } diff --git a/src/lib.rs b/src/lib.rs index 808870a..feb3ac2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,14 +92,14 @@ pub struct AmbiguousLanguages([bool; language::MAX_NB_LANGUAGES]); impl AmbiguousLanguages { /// Presents the possible languages in the form of a slice of booleans - /// that correspond to the occurrences in [Language::all()]. + /// that correspond to the occurrences in [Language::ALL]. pub fn as_bools(&self) -> &[bool; language::MAX_NB_LANGUAGES] { &self.0 } /// An iterator over the possible languages. pub fn iter(&self) -> impl Iterator + '_ { - Language::all().iter().enumerate().filter(move |(i, _)| self.0[*i]).map(|(_, l)| *l) + Language::ALL.iter().enumerate().filter(move |(i, _)| self.0[*i]).map(|(_, l)| *l) } /// Returns a vector of the possible languages. @@ -337,7 +337,7 @@ impl Mnemonic { } /// Returns an iterator over the words of the [Mnemonic]. - #[deprecated(note = "Use Mnemonic::words instead")] + #[deprecated(since = "2.1.0", note = "Use Mnemonic::words instead")] pub fn word_iter(&self) -> impl Iterator + Clone + '_ { self.words() } @@ -365,7 +365,7 @@ impl Mnemonic { /// See documentation on [Mnemonic::language_of] for more info. fn language_of_iter<'a, W: Iterator>(words: W) -> Result { let mut words = words.peekable(); - let langs = Language::all(); + let langs = Language::ALL; { // Start scope to drop first_word so that words can be reborrowed later. let first_word = words.peek().ok_or(Error::BadWordCount(0))?; @@ -530,8 +530,8 @@ impl Mnemonic { let mut cow = s.into(); Mnemonic::normalize_utf8_cow(&mut cow); - let language = if Language::all().len() == 1 { - Language::all()[0] + let language = if Language::ALL.len() == 1 { + Language::ALL[0] } else { Mnemonic::language_of(cow.as_ref())? }; @@ -680,7 +680,7 @@ mod tests { #[cfg(feature = "rand")] #[test] fn test_language_of() { - for lang in Language::all() { + for lang in Language::ALL { let m = Mnemonic::generate_in(*lang, 24).unwrap(); assert_eq!(*lang, Mnemonic::language_of_iter(m.words()).unwrap()); assert_eq!( @@ -698,10 +698,10 @@ mod tests { let mut present = [false; language::MAX_NB_LANGUAGES]; let mut present_vec = Vec::new(); let mut alternate = true; - for i in 0..Language::all().len() { + for i in 0..Language::ALL.len() { present[i] = alternate; if alternate { - present_vec.push(Language::all()[i]); + present_vec.push(Language::ALL[i]); } alternate = !alternate; }