use std::fmt::Display; pub struct Match { pub file_name: String, pub line_number: usize, pub text: String, } pub struct Matches { pub items: Vec, pub pattern: String, } impl Matches { pub fn is_empty(&self) -> bool { self.items.is_empty() } pub fn append(&mut self, matches: &mut Self) -> () { self.items.append(&mut matches.items); } } 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)?; } Ok(()) } }