piazin_grrs/lib.rs
1use std::io;
2
3// io::Result<()> ref: https://www.reddit.com/r/rust/comments/6b8iuy/comment/dhkon28/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
4// mut writer: impl std::io::Write podemos passar qualquer tipo que implemente std::io::Write ref: https://doc.rust-lang.org/1.39.0/std/io/trait.Write.html
5pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) -> io::Result<()> {
6 for line in content.lines() {
7 if line.contains(pattern) {
8 // a macro writeln! retorna um io::Result<T, std::io::Error>
9 writeln!(writer, "{}", line)?
10 }
11 }
12
13 Ok(())
14}
15