diff --git a/src/regex.rs b/src/regex.rs index ebd9bbd..058f196 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::{ self, Lines, BufRead, BufReader }; use std::path::Path; -use regex::{RegexSet}; +use regex::RegexSet; use crate::token::*; // The output is wrapped in a Result to allow matching on errors diff --git a/src/token.rs b/src/token.rs index 2f6a00b..ef51854 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,5 +1,5 @@ -use chrono::NaiveDate; use std::fmt; +use chrono::NaiveDate; use colored::Colorize; use regex::Regex; @@ -45,21 +45,12 @@ impl Token { let year = capture.get(1).unwrap().as_str().parse::().unwrap(); let month = capture.get(2).unwrap().as_str().parse::().unwrap(); let day = capture.get(3).unwrap().as_str().parse::().unwrap(); - t.date = NaiveDate::from_ymd_opt(year, month, day); } - // let date: Vec<&str> = field.split('/').collect(); - // let year = date[0].parse::().unwrap(); - // let month = date[1].parse::().unwrap(); - // let day = date[2].parse::().unwrap(); - // t.date = NaiveDate::from_ymd_opt(year, month, day); } else if member_regex.is_match(field) { t.member = Some(field.chars().skip(1).collect::()); } else { - t.comment = match t.comment { - None => Some(field.to_string()), - Some(comment) => Some(format!("{} {}", comment, field)), - }; + t.comment = t.comment.map_or_else(|| Some(field.to_string()), |comment| Some(format!("{} {}", comment, field))); } }