From 71a67fec6da0240100afa9baa44ededf35ec5ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 28 Sep 2017 17:24:53 +0200 Subject: [PATCH 1/2] Expose words and add Display to Error. --- Cargo.toml | 2 +- src/lib.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52d8752..bf679b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-wordlist" -version = "1.1.0" +version = "1.2.0" description = "Word list used to generate brain wallets for Parity." license = "GPL-3.0" authors = ["Parity Technologies "] diff --git a/src/lib.rs b/src/lib.rs index bef385e..9558ead 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. From af439c85246b36aef59b332b5ef013becb625ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 28 Sep 2017 17:27:16 +0200 Subject: [PATCH 2/2] Update readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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