Skip to content

Commit b100bf3

Browse files
authored
Merge pull request #54 from rust-bitcoin/release-2.1.0
Release 2.1.0
2 parents 627aa96 + 125abeb commit b100bf3

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
# v2.1.0
5+
6+
- Add support for Portuguese as per addition to BIP.
7+
- Add constant Language::ALL and deprecate Language::all()
8+
- Add Mnemonic::words and deprecate Mnemonic::word_iter
9+
- Add Mnemonic::word_indices
10+
- Use `rand_core` if `rand` feature is not set
11+
- Add `alloc` feature to gate `unicode-normalization`
12+
413
# v2.0.0
514

615
- Set Rust edition to 2018

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bip39"
3-
version = "2.0.0"
3+
version = "2.1.0"
44
authors = ["Steven Roose <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-bip39/"

src/language/mod.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,33 @@ impl Default for Language {
6969
impl Language {
7070
/// The list of supported languages.
7171
/// Language support is managed by compile features.
72+
pub const ALL: &'static [Language] = &[
73+
Language::English,
74+
#[cfg(feature = "chinese-simplified")]
75+
Language::SimplifiedChinese,
76+
#[cfg(feature = "chinese-traditional")]
77+
Language::TraditionalChinese,
78+
#[cfg(feature = "czech")]
79+
Language::Czech,
80+
#[cfg(feature = "french")]
81+
Language::French,
82+
#[cfg(feature = "italian")]
83+
Language::Italian,
84+
#[cfg(feature = "japanese")]
85+
Language::Japanese,
86+
#[cfg(feature = "korean")]
87+
Language::Korean,
88+
#[cfg(feature = "portuguese")]
89+
Language::Portuguese,
90+
#[cfg(feature = "spanish")]
91+
Language::Spanish,
92+
];
93+
94+
/// The list of supported languages.
95+
/// Language support is managed by compile features.
96+
#[deprecated(since = "2.1.0", note = "use constant Language::ALL instead")]
7297
pub fn all() -> &'static [Language] {
73-
&[
74-
Language::English,
75-
#[cfg(feature = "chinese-simplified")]
76-
Language::SimplifiedChinese,
77-
#[cfg(feature = "chinese-traditional")]
78-
Language::TraditionalChinese,
79-
#[cfg(feature = "czech")]
80-
Language::Czech,
81-
#[cfg(feature = "french")]
82-
Language::French,
83-
#[cfg(feature = "italian")]
84-
Language::Italian,
85-
#[cfg(feature = "japanese")]
86-
Language::Japanese,
87-
#[cfg(feature = "korean")]
88-
Language::Korean,
89-
#[cfg(feature = "portuguese")]
90-
Language::Portuguese,
91-
#[cfg(feature = "spanish")]
92-
Language::Spanish,
93-
]
98+
Language::ALL
9499
}
95100

96101
/// The word list for this language.
@@ -306,7 +311,7 @@ mod tests {
306311
// Afterwards, we make sure that no word maps to multiple languages
307312
// if either of those is guaranteed to have unique words.
308313
let mut words: HashMap<&str, Vec<Language>> = HashMap::new();
309-
for lang in Language::all().iter() {
314+
for lang in Language::ALL.iter() {
310315
for word in lang.word_list().iter() {
311316
words.entry(word).or_insert(Vec::new()).push(*lang);
312317
}

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ pub struct AmbiguousLanguages([bool; language::MAX_NB_LANGUAGES]);
9292

9393
impl AmbiguousLanguages {
9494
/// Presents the possible languages in the form of a slice of booleans
95-
/// that correspond to the occurrences in [Language::all()].
95+
/// that correspond to the occurrences in [Language::ALL].
9696
pub fn as_bools(&self) -> &[bool; language::MAX_NB_LANGUAGES] {
9797
&self.0
9898
}
9999

100100
/// An iterator over the possible languages.
101101
pub fn iter(&self) -> impl Iterator<Item = Language> + '_ {
102-
Language::all().iter().enumerate().filter(move |(i, _)| self.0[*i]).map(|(_, l)| *l)
102+
Language::ALL.iter().enumerate().filter(move |(i, _)| self.0[*i]).map(|(_, l)| *l)
103103
}
104104

105105
/// Returns a vector of the possible languages.
@@ -337,7 +337,7 @@ impl Mnemonic {
337337
}
338338

339339
/// Returns an iterator over the words of the [Mnemonic].
340-
#[deprecated(note = "Use Mnemonic::words instead")]
340+
#[deprecated(since = "2.1.0", note = "Use Mnemonic::words instead")]
341341
pub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone + '_ {
342342
self.words()
343343
}
@@ -365,7 +365,7 @@ impl Mnemonic {
365365
/// See documentation on [Mnemonic::language_of] for more info.
366366
fn language_of_iter<'a, W: Iterator<Item = &'a str>>(words: W) -> Result<Language, Error> {
367367
let mut words = words.peekable();
368-
let langs = Language::all();
368+
let langs = Language::ALL;
369369
{
370370
// Start scope to drop first_word so that words can be reborrowed later.
371371
let first_word = words.peek().ok_or(Error::BadWordCount(0))?;
@@ -530,8 +530,8 @@ impl Mnemonic {
530530
let mut cow = s.into();
531531
Mnemonic::normalize_utf8_cow(&mut cow);
532532

533-
let language = if Language::all().len() == 1 {
534-
Language::all()[0]
533+
let language = if Language::ALL.len() == 1 {
534+
Language::ALL[0]
535535
} else {
536536
Mnemonic::language_of(cow.as_ref())?
537537
};
@@ -680,7 +680,7 @@ mod tests {
680680
#[cfg(feature = "rand")]
681681
#[test]
682682
fn test_language_of() {
683-
for lang in Language::all() {
683+
for lang in Language::ALL {
684684
let m = Mnemonic::generate_in(*lang, 24).unwrap();
685685
assert_eq!(*lang, Mnemonic::language_of_iter(m.words()).unwrap());
686686
assert_eq!(
@@ -698,10 +698,10 @@ mod tests {
698698
let mut present = [false; language::MAX_NB_LANGUAGES];
699699
let mut present_vec = Vec::new();
700700
let mut alternate = true;
701-
for i in 0..Language::all().len() {
701+
for i in 0..Language::ALL.len() {
702702
present[i] = alternate;
703703
if alternate {
704-
present_vec.push(Language::all()[i]);
704+
present_vec.push(Language::ALL[i]);
705705
}
706706
alternate = !alternate;
707707
}

0 commit comments

Comments
 (0)