2026-07-27 09:53:58 +00:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
|
|
pub struct Match {
|
|
|
|
|
pub file_name: String,
|
|
|
|
|
pub line_number: usize,
|
|
|
|
|
pub text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Matches {
|
|
|
|
|
pub items: Vec<Match>,
|
|
|
|
|
pub pattern: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for Matches {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
2026-07-27 10:04:12 +00:00
|
|
|
writeln!(f, "Matches for pattern {}:", self.pattern)?;
|
2026-07-27 09:53:58 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
write!(f, "{}", "")
|
|
|
|
|
}
|
|
|
|
|
}
|