diff --git a/src/matches.rs b/src/matches.rs index 9d6093c..c1614ca 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -1,7 +1,7 @@ -use std::fmt::Display; +use std::{fmt::Display, path::PathBuf}; pub struct Match { - pub file_name: String, + pub file_path: PathBuf, pub line_number: usize, pub text: String, } @@ -23,7 +23,7 @@ impl Matches { impl Display for Match { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}: line {}: {}", self.file_name, self.line_number, self.text) + write!(f, "{}: line {}: {}", self.file_path.display(), self.line_number, self.text) } } diff --git a/src/parser.rs b/src/parser.rs index 903a00b..21af148 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -46,12 +46,12 @@ pub fn read_lines( Ok(reader.lines()) } -fn get_file_name_from_path(file_path: &Path) -> String { - match file_path.file_name() { - Some(name) => name.to_string_lossy().to_string(), - None => String::from("unknown"), - } -} +// fn get_file_name_from_path(file_path: &Path) -> String { +// match file_path.file_name() { +// Some(name) => name.to_string_lossy().to_string(), +// None => String::from("unknown"), +// } +// } pub fn match_pattern( iter: impl Iterator>, @@ -65,11 +65,7 @@ pub fn match_pattern( let line = line?; if regex.is_match(&line) { - let m = Match { - line_number: idx + 1, - text: line, - file_name: get_file_name_from_path(file_path), - }; + let m = Match { line_number: idx + 1, text: line, file_path: PathBuf::from(file_path) }; matches.push(m); }