Refactoring: Use function chaining rather than matching

This commit is contained in:
Matthias Beyer 2018-01-04 23:09:30 +01:00
parent e7d5e9ebc2
commit a386d50df3
2 changed files with 11 additions and 10 deletions

View file

@ -45,11 +45,10 @@ impl<'a> Iterator for GetTimeTrackIter<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.inner.next().map(|sid| { self.inner.next().map(|sid| {
match self.store.get(sid).chain_err(|| TTEK::StoreReadError) { self.store
Ok(None) => Err(TTE::from_kind(TTEK::StoreReadError)), .get(sid)
Ok(Some(s)) => Ok(s), .chain_err(|| TTEK::StoreReadError)?
Err(e) => Err(e) .ok_or(TTE::from_kind(TTEK::StoreReadError))
}
}) })
} }
} }

View file

@ -65,11 +65,13 @@ impl TimeTracking for Entry {
fn get_timetrack_tag(&self) -> Result<TTT> { fn get_timetrack_tag(&self) -> Result<TTT> {
self.get_header() self.get_header()
.read(DATE_TIME_TAG_HEADER_PATH) .read(DATE_TIME_TAG_HEADER_PATH)
.chain_err(|| TTEK::HeaderReadError) .chain_err(|| TTEK::HeaderReadError)?
.and_then(|value| match value { .ok_or(TTE::from_kind(TTEK::HeaderReadError))
Some(&Value::String(ref s)) => Ok(s.clone().into()), .and_then(|v| {
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)), v.as_str()
_ => Err(TTE::from_kind(TTEK::HeaderReadError)) .map(String::from)
.map(Into::into)
.ok_or(TTE::from_kind(TTEK::HeaderFieldTypeError))
}) })
} }