From 93cddf69d2f2648fe6e8c00e5c7df51ef79b16de Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 18 Nov 2018 12:04:33 +0000 Subject: Formatting improvements from cargo fmt --- src/main.rs | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src') 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

(filename: &P) -> Result, io::Error> - where P: AsRef +where + P: AsRef, { 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, 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::() { - Ok(n) => num_words = n, - Err(_e) => { - println!("Please enter an integer for the -w flag"); - return; - } + Some(x) => match x.parse::() { + 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; } } -- cgit v1.2.3