34 lines
761 B
Rust
34 lines
761 B
Rust
|
|
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 {
|
||
|
|
writeln!(f, "Matches for pattern {}:", self.pattern);
|
||
|
|
|
||
|
|
for (idx, item) in self.items.iter().enumerate() {
|
||
|
|
if idx > 0 {
|
||
|
|
writeln!(f)?;
|
||
|
|
}
|
||
|
|
|
||
|
|
write!(f, "{}", item);
|
||
|
|
}
|
||
|
|
write!(f, "{}", "")
|
||
|
|
}
|
||
|
|
}
|