From ac8bcde2395e0f954c5cb405064bd21ab76bbe3e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 14 May 2016 18:59:15 +0200 Subject: [PATCH] Remove unwrap() hell by matching --- libimagstore/src/store.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index ed945a7f..0224eb77 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -1192,25 +1192,22 @@ impl Entry { ").unwrap(); } - let matches = RE.captures(s); + let matches = match RE.captures(s) { + None => return Err(StoreError::new(StoreErrorKind::MalformedEntry, None)), + Some(s) => s, + }; - if matches.is_none() { - return Err(StoreError::new(StoreErrorKind::MalformedEntry, None)); - } + let header = match matches.name("header") { + None => return Err(StoreError::new(StoreErrorKind::MalformedEntry, None)), + Some(s) => s + }; - let matches = matches.unwrap(); - - let header = matches.name("header"); let content = matches.name("content").unwrap_or(""); - if header.is_none() { - return Err(StoreError::new(StoreErrorKind::MalformedEntry, None)); - } - debug!("Header and content found. Yay! Building Entry object now"); Ok(Entry { location: loc.into_storeid(), - header: try!(EntryHeader::parse(header.unwrap())), + header: try!(EntryHeader::parse(header)), content: content.into(), }) }