aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs52
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;
}
}