diff options
author | Michaël Ball <michael.ball@gmail.com> | 2018-11-18 12:18:13 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2018-11-18 12:18:13 +0000 |
commit | 002f6c8f48c46f0d79c65a9d47f893859b070b21 (patch) | |
tree | 973d03cba05a84b591ca050a4ff65556ea9f0823 /src | |
parent | 75b28f31e5603c39215b7c91b35610269c7fd0ed (diff) | |
parent | c7e59c4143077b9e15e3d6dc3fe1a3523cd0eebb (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs index c78441e..c8a1e01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,17 +4,19 @@ extern crate rand; use getopts::Options; use rand::{thread_rng, Rng}; use std::env; -use std::vec::Vec; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::Path; +use std::vec::Vec; fn lines_from_file<P>(filename: &P) -> Result<Vec<String>, io::Error> - where P: AsRef<Path> +where + P: AsRef<Path>, { let file = try!(File::open(filename)); let buf = BufReader::new(file); - Ok(buf.lines() + Ok(buf + .lines() .map(|l| l.expect("Could not parse line")) .collect()) } @@ -40,11 +42,13 @@ fn random_words_from_dictionary(dictionary: &Vec<String>, words: &usize) -> Vec< #[test] fn test_random_words_from_dictionary() { - let test_dict = vec!["This".to_string(), - "is".to_string(), - "a".to_string(), - "test".to_string(), - "vector".to_string()]; + let test_dict = vec![ + "This".to_string(), + "is".to_string(), + "a".to_string(), + "test".to_string(), + "vector".to_string(), + ]; let num_words = 3; let new_vec = random_words_from_dictionary(&test_dict, &num_words); @@ -56,10 +60,12 @@ fn main() { let program = args[0].clone(); let mut opts = Options::new(); - opts.optopt("w", - "", - "number of words to use in passphrase, default is 4", - "WORDS"); + opts.optopt( + "w", + "", + "number of words to use in passphrase, default is 4", + "WORDS", + ); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -77,15 +83,13 @@ fn main() { let num_words; match words_opt { - Some(x) => { - match x.parse::<usize>() { - Ok(n) => num_words = n, - Err(_e) => { - println!("Please enter an integer for the -w flag"); - return; - } + Some(x) => match x.parse::<usize>() { + Ok(n) => num_words = n, + Err(_e) => { + println!("Please enter an integer for the -w flag"); + return; } - } + }, None => num_words = 4, } @@ -94,9 +98,11 @@ fn main() { match lines_from_file(&input) { Ok(n) => lines = n, Err(_e) => { - println!("Cannot read file {}. Please ensure it exists and you have permission to \ - read it.", - input); + println!( + "Cannot read file {}. Please ensure it exists and you have permission to \ + read it.", + input + ); return; } } |