diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-05-10 14:43:45 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-05-11 10:47:59 +0200 |
commit | 79fa2aebeb9c5daafd72e061466de97c4fcacc36 (patch) | |
tree | 6595c708b5c4765a791d3e1bf88009c0072ff18d /src/log/parser.rs | |
parent | ca55fb3a9cb77b2ed22335adfe9f7bc986c37aaa (diff) |
Refactor: Implement FromStr
Instead of having a function `&str -> Result<Self>` on the type, implement the
`std::str::FromStr` trait to be more rusty here.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/log/parser.rs')
-rw-r--r-- | src/log/parser.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/log/parser.rs b/src/log/parser.rs index 6dcb9e3..764b732 100644 --- a/src/log/parser.rs +++ b/src/log/parser.rs @@ -38,16 +38,19 @@ where pub struct ParsedLog(Vec<LogItem>); -impl ParsedLog { - pub fn build_from<S: AsRef<str>>(s: S) -> Result<Self> { +impl FromStr for ParsedLog { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result<Self> { let p = parser(); - s.as_ref() - .lines() + s.lines() .map(|line| p.parse(line.as_bytes()).map_err(Error::from)) .collect::<Result<Vec<_>>>() .map(ParsedLog) } +} +impl ParsedLog { pub fn is_successfull(&self) -> Option<bool> { self.0 .iter() |