diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 10:17:57 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-03 10:37:32 +0100 |
commit | c757f69350f5528df4386705429ed7ae45bc6c01 (patch) | |
tree | 0a1725f2909b472cfa6c8d7ec4c89c056fcb632f | |
parent | c38486851ae05c86c775c3acdff7aff8106bbdc2 (diff) |
Impl TryFrom<ConfigDeser> for Config
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/config.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/config.rs b/src/config.rs index 7238eb9..c319872 100644 --- a/src/config.rs +++ b/src/config.rs @@ -128,20 +128,25 @@ pub struct Config { } impl Config { + pub fn load(path: PathBuf) -> Result<Self> { + ConfigDeser::load(path).and_then(Self::try_from) + } +} + +impl TryFrom<ConfigDeser> for Config { + type Error = crate::error::Error; /// Lets serde do the deserialization, and transforms the given data /// for later access - pub fn load(path: PathBuf) -> Result<Self> { - let conf_deser = ConfigDeser::load(path)?; - - let mut l_items : Vec<LogItem> = Vec::new(); - for lid in conf_deser.get_items() { - l_items.push(LogItem::try_from((*lid).clone())?); - } + fn try_from(conf_deser: ConfigDeser) -> std::result::Result<Self, Self::Error> { + let l_items: Vec<LogItem> = conf_deser.item + .into_iter() + .map(LogItem::try_from) + .collect::<Result<_>>()?; // combines all aliases into one Vec for the /search endpoint let mut all_als : Vec<String> = Vec::new(); - for li in &l_items { + for li in l_items.iter() { for als in li.aliases() { all_als.push((*als).clone()); } |