2026-07-27 18:32:25 +00:00
|
|
|
use std::{fmt::Display, path::PathBuf};
|
2026-07-27 09:53:58 +00:00
|
|
|
|
|
|
|
|
pub struct Match {
|
2026-07-27 18:32:25 +00:00
|
|
|
pub file_path: PathBuf,
|
2026-07-27 09:53:58 +00:00
|
|
|
pub line_number: usize,
|
|
|
|
|
pub text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Matches {
|
|
|
|
|
pub items: Vec<Match>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 10:50:12 +00:00
|
|
|
impl Matches {
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
|
self.items.is_empty()
|
|
|
|
|
}
|
2026-07-27 16:38:46 +00:00
|
|
|
|
2026-07-27 18:19:14 +00:00
|
|
|
pub fn append(&mut self, matches: &mut Self) {
|
2026-07-27 16:38:46 +00:00
|
|
|
self.items.append(&mut matches.items);
|
|
|
|
|
}
|
2026-07-27 10:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-27 09:53:58 +00:00
|
|
|
impl Display for Match {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
2026-07-27 18:32:25 +00:00
|
|
|
write!(f, "{}: line {}: {}", self.file_path.display(), self.line_number, self.text)
|
2026-07-27 09:53:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for Matches {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
for (idx, item) in self.items.iter().enumerate() {
|
|
|
|
|
if idx > 0 {
|
|
|
|
|
writeln!(f)?;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 10:04:12 +00:00
|
|
|
write!(f, "{}", item)?;
|
2026-07-27 09:53:58 +00:00
|
|
|
}
|
2026-07-27 10:05:19 +00:00
|
|
|
|
|
|
|
|
Ok(())
|
2026-07-27 09:53:58 +00:00
|
|
|
}
|
|
|
|
|
}
|