Refactoring: Use function chaining rather than matching

This commit is contained in:
Matthias Beyer 2018-01-04 23:09:30 +01:00
parent a386d50df3
commit dd66936e48

View file

@ -25,7 +25,6 @@ use error::Result;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use uuid::Uuid; use uuid::Uuid;
use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
pub trait Task { pub trait Task {
@ -34,14 +33,13 @@ pub trait Task {
impl Task for Entry { impl Task for Entry {
fn get_uuid(&self) -> Result<Uuid> { fn get_uuid(&self) -> Result<Uuid> {
match self.get_header().read("todo.uuid") { self.get_header()
Ok(Some(&Value::String(ref uuid))) => { .read("todo.uuid")
Uuid::parse_str(uuid).chain_err(|| TEK::UuidParserError) .chain_err(|| TEK::StoreError)?
}, .ok_or(TE::from_kind(TEK::HeaderFieldMissing))?
Ok(Some(_)) => Err(TE::from_kind(TEK::HeaderTypeError)), .as_str()
Ok(None) => Err(TE::from_kind(TEK::HeaderFieldMissing)), .ok_or(TE::from_kind(TEK::HeaderTypeError))
Err(e) => Err(e).chain_err(|| TEK::StoreError), .and_then(|u| Uuid::parse_str(u).chain_err(|| TEK::UuidParserError))
}
} }
} }