diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 10:14:02 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 10:37:32 +0100 |
commit | c38486851ae05c86c775c3acdff7aff8106bbdc2 (patch) | |
tree | cf655b5eeceb4c4efb2b59067b0b60c6090904ab | |
parent | 47b184651c226a8ee3679cfac3936f62640c8c99 (diff) |
Use TryFrom for LogItemDeser -> LogItem conversion
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/config.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs index 465d802..7238eb9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ extern crate log; extern crate toml; use std::path::PathBuf; +use std::convert::TryFrom; use regex::Regex; use error::*; use getset::Getters; @@ -77,10 +78,11 @@ pub struct LogItem { aliases : Vec<String>, } -impl LogItem { +impl TryFrom<LogItemDeser> for LogItem { + type Error = crate::error::Error; /// Transforms a LogItemDeser into a more immediately usable LogItem - fn from_log_item_deser(lid : LogItemDeser) -> Result<LogItem> { + fn try_from(lid : LogItemDeser) -> std::result::Result<LogItem, Self::Error> { // first capture is the whole match and nameless // second capture is always the timestamp let cnames : Vec<String> = lid.regex @@ -134,7 +136,7 @@ impl Config { let mut l_items : Vec<LogItem> = Vec::new(); for lid in conf_deser.get_items() { - l_items.push(LogItem::from_log_item_deser((*lid).clone())?); + l_items.push(LogItem::try_from((*lid).clone())?); } // combines all aliases into one Vec for the /search endpoint |