Skip to content

Conversation

@stevenroose
Copy link
Collaborator

Also bumps the version to v1.0.1

@stevenroose
Copy link
Collaborator Author

Since a Mnemonic object only exists after parsing and validating, the only possible error from Mnemonic::language is Error::AmbiguousLanguages, we could actually do this:

diff --git a/src/lib.rs b/src/lib.rs
index 0beb726..c1eb750 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -362,8 +362,12 @@ 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.
-       pub fn language(&self) -> Result<Language, Error> {
-               Mnemonic::language_of_iter(self.word_iter())
+       pub fn language(&self) -> Result<Language, AmbiguousLanguages> {
+               match Mnemonic::language_of_iter(self.word_iter()) {
+                       Ok(lang) => Ok(lang),
+                       Err(Error::AmbiguousLanguages(ambi)) => Err(ambi),
+                       Err(_) => unreachable!("the mnemonic is already validated"),
+               }
        }
 
        /// Parse a mnemonic in normalized UTF8 in the given language.

@stevenroose
Copy link
Collaborator Author

Superceded by #11.

@stevenroose stevenroose closed this Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants