use recap::Recap; use serde::Deserialize; use std::error::Error; #[derive(Debug, Deserialize, Recap)] #[recap(regex = r#"(?x) (?P\d+) \s+ (?Ptrue|false) \s+ (?P\S+) "#)] #[allow(dead_code)] struct LogEntry { foo: usize, bar: bool, baz: String, } fn main() -> Result<(), Box> { let logs = r#"1 true hello 2 false world"#; for line in logs.lines() { if LogEntry::is_match(line) { let entry: LogEntry = line.parse()?; println!("{:#?}", entry); } } Ok(()) }