diff --git a/README.md b/README.md index 044a576..c25d210 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Parity Brain Wallets wordlist library -[Rust Documentation](https://docs.rs/parity-wordlist/1.1.0/parity_wordlist/) +[Rust Documentation](https://docs.rs/parity-wordlist/) # RUST diff --git a/src/lib.rs b/src/lib.rs index ba328de..71b3b06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,12 +24,14 @@ extern crate lazy_static; extern crate itertools; extern crate rand; +use std::fmt; use std::collections::HashSet; use itertools::Itertools; use rand::{Rng, OsRng}; +/// The list of dictionary words. // the wordlist JSON also happens to be valid Rust syntax for an array constant. -const WORDS: &'static [&'static str] = &include!("../res/wordlist.json"); +pub const WORDS: &'static [&'static str] = &include!("../res/wordlist.json"); /// Generate a string which is a random phrase of a number of lowercase words. /// @@ -50,6 +52,15 @@ pub enum Error { WordNotFromDictionary(String), } +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::PhraseTooShort(len) => writeln!(fmt, "The phrase is too short ({})", len), + Error::WordNotFromDictionary(ref word) => writeln!(fmt, "The word '{}' does not come from the dictionary.", word), + } + } +} + /// Validates given phrase and checks if: /// 1. All the words are coming from the dictionary. /// 2. There are at least `expected_no_of_words` in the phrase.