From dfbb8889a7c96a7c4b7a7ed103fbc5d49d55d461 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 26 Jul 2020 15:01:18 +0800 Subject: [PATCH] style: code style --- src/main.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9e6f35a..0222f0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,6 @@ fn main() -> std::io::Result<()> { parsers.push(Parser::new(String::from("//fix"), Box::from(|x : Vec| x.last().unwrap() == &'\n'))); - //loop on every file within the current dir for entry in match glob(&path) { Ok(entry) => entry, @@ -84,23 +83,22 @@ fn main() -> std::io::Result<()> { let mut path = String::from(dirs::home_dir().unwrap().to_str().unwrap()); path.push_str("/.cargo/todo_config"); // println!("{}",path); - fn read_lines

(filename: P) -> io::Result>> - where P: AsRef, { - let file = match File::open(&filename){ - Ok(line) => line, - Err(_) => { - println!("{}", "File '~/.cargo/todo_config' not found, creating it".red()); - let mut f = OpenOptions::new().write(true).read(true).create(true).open(&filename).unwrap(); - f.write_all(b"^s*//s*todo\\b\n").unwrap(); - f.write_all(b"^s*//s*fix\\b\n").unwrap(); - f.write_all(b"^s*//s*fixme\\b\n").unwrap(); - return read_lines(filename); - } - }; - Ok(io::BufReader::new(file).lines()) + fn read_lines

(filename: P) -> io::Result>> where P: AsRef { + let file = match File::open(&filename) { + Ok(line) => line, + Err(_) => { + println!("{}", "File '~/.cargo/todo_config' not found, creating it".red()); + let mut f = OpenOptions::new().write(true).read(true).create(true).open(&filename).unwrap(); + f.write_all(b"^s*//s*todo\\b\n").unwrap(); + f.write_all(b"^s*//s*fix\\b\n").unwrap(); + f.write_all(b"^s*//s*fixme\\b\n").unwrap(); + return read_lines(filename); + } + }; + Ok(io::BufReader::new(file).lines()) } - let mut regex = Vec::new(); + let mut regex = vec![]; for line in read_lines(path).unwrap() { let line = line.unwrap(); regex.push(line); @@ -115,14 +113,16 @@ fn main() -> std::io::Result<()> { println!("Couldn't access files. Error {}", e); Err(e).unwrap() } - } { + } + + { let path = entry.unwrap(); let path = Path::new(&path).strip_prefix(env::current_dir().unwrap().to_str().unwrap()).unwrap(); // println!("{}", path.to_str().unwrap()); if !path.starts_with("target/") { let path = path.to_str().unwrap(); - if matches.occurrences_of("verbose") == 0 || matches.occurrences_of("verbose") == 2{ + if matches.occurrences_of("verbose") == 0 || matches.occurrences_of("verbose") == 2 { match regex_parser(path, regex.clone(), 2){ Ok(mut t) => { tokens.append(&mut t); @@ -188,7 +188,7 @@ fn main() -> std::io::Result<()> { for i in tokens{ // println!("{}", i); for y in &filters { - if i.member.clone().is_some() && i.member.clone().unwrap() == *y.to_string(){ + if i.member.clone().is_some() && i.member.clone().unwrap() == *y.to_string() { println!("pushing"); new_tokens.push(i.clone()); break; @@ -221,7 +221,7 @@ fn main() -> std::io::Result<()> { if i.keyword == excludes[y] { break; } - else if y == excludes.len() -1{ + else if y == excludes.len() -1 { new_tokens.push(i.clone()); } }