Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.1.0 #54

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bip39"
version = "2.0.0"
version = "2.1.0"
authors = ["Steven Roose <steven@stevenroose.org>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bip39/"
Expand Down
49 changes: 27 additions & 22 deletions src/language/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Language>> = 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);
}
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Language> + '_ {
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.
Expand Down Expand Up @@ -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<Item = &'static str> + Clone + '_ {
self.words()
}
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Mnemonic {
/// See documentation on [Mnemonic::language_of] for more info.
fn language_of_iter<'a, W: Iterator<Item = &'a str>>(words: W) -> Result<Language, Error> {
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))?;
Expand Down Expand Up @@ -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())?
};
Expand Down Expand Up @@ -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!(
Expand All @@ -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;
}
Expand Down
Loading