Skip to content

Commit

Permalink
Expose words and add Display to Error. (#10)
Browse files Browse the repository at this point in the history
* Expose words and add Display to Error.

* Update readme.
  • Loading branch information
tomusdrw authored Sep 28, 2017
1 parent 4404e3a commit 75941c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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.
Expand Down

0 comments on commit 75941c7

Please sign in to comment.