Remove unwrap() hell by matching
This commit is contained in:
parent
11021906b3
commit
ac8bcde239
1 changed files with 9 additions and 12 deletions
|
@ -1192,25 +1192,22 @@ impl Entry {
|
||||||
").unwrap();
|
").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() {
|
let header = match matches.name("header") {
|
||||||
return Err(StoreError::new(StoreErrorKind::MalformedEntry, None));
|
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("");
|
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");
|
debug!("Header and content found. Yay! Building Entry object now");
|
||||||
Ok(Entry {
|
Ok(Entry {
|
||||||
location: loc.into_storeid(),
|
location: loc.into_storeid(),
|
||||||
header: try!(EntryHeader::parse(header.unwrap())),
|
header: try!(EntryHeader::parse(header)),
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue