I'm learning Rust and trying to apply a regex inside for loop reading a line.
extern crate regex;
use regex::Regex;
use std::fs::File;
use std::io::{BufReader, Result, BufRead};
fn main() -> Result<()> {
let file = File::open("logs.log")?;
let reader = BufReader::new(file);
let re = Regex::new(r"^\w{3}\s{1,2}\d{1,2}\s(?:\d{2}:){2}\d{2}").unwrap();
for line in reader.lines() {
println!("{}", re.is_match(line));
}
Ok(())
}
using cargo run I receive the error above
--> src/main.rs:14:36
|
14 | println!("{}", re.is_match(line));
| ^^^^ expected `&str`, found enum `std::result::Result`
|
= note: expected reference `&str`
found enum `std::result::Result<String, std::io::Error>`
using rustc file.rs, receive this
| extern crate regex;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
is that the right way to applying regex ?