style: code style

This commit is contained in:
2020-07-26 15:01:18 +08:00
parent 748fb8eca0
commit dfbb8889a7

View File

@@ -54,7 +54,6 @@ fn main() -> std::io::Result<()> {
parsers.push(Parser::new(String::from("//fix"), Box::from(|x : Vec<char>| 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<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
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<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>> where P: AsRef<Path> {
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());
}
}