From dff8d777bf02a6e11e4d3f2851f82fceedb18310 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 1 Apr 2021 13:27:05 +0100 Subject: [PATCH] Add Mnemonic::language and make language_of public --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/lib.rs | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeed3a9..e2c136e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +# v1.0.1 + +- Add static `Mnemonic::language_of` method. +- Add `Mnemonic::language` getter method. # v1.0.0 diff --git a/Cargo.toml b/Cargo.toml index 3836a0e..cd4c2aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bip39" -version = "1.0.0" +version = "1.0.1" authors = ["Steven Roose "] license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-bip39/" diff --git a/src/lib.rs b/src/lib.rs index 3f4ffdb..0beb726 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -352,10 +352,20 @@ impl Mnemonic { /// word lists. In the extremely unlikely case that a word list can be /// interpreted in multiple languages, an [Error::AmbiguousLanguages] is /// returned, containing the possible languages. - fn language_of>(mnemonic: S) -> Result { + pub fn language_of>(mnemonic: S) -> Result { Mnemonic::language_of_iter(mnemonic.as_ref().split_whitespace()) } + /// Get this mnemonic's language. + /// + /// Some word lists don't guarantee that their words don't occur in other + /// word lists. In the extremely unlikely case that a word list can be + /// interpreted in multiple languages, an [Error::AmbiguousLanguages] is + /// returned, containing the possible languages. + pub fn language(&self) -> Result { + Mnemonic::language_of_iter(self.word_iter()) + } + /// Parse a mnemonic in normalized UTF8 in the given language. pub fn parse_in_normalized(language: Language, s: &str) -> Result { let nb_words = s.split_whitespace().count();