Remove unwrap() calls by matching

This commit is contained in:
Matthias Beyer 2016-05-14 19:29:14 +02:00
parent 81810dbcc8
commit 0b7f815104

View file

@ -901,23 +901,21 @@ impl EntryHeader {
} }
pub fn read_with_sep(&self, spec: &str, splitchr: char) -> Result<Option<Value>> { pub fn read_with_sep(&self, spec: &str, splitchr: char) -> Result<Option<Value>> {
let tokens = EntryHeader::tokenize(spec, splitchr); let tokens = match EntryHeader::tokenize(spec, splitchr) {
if tokens.is_err() { // return parser error if any Err(e) => return Err(e),
return Err(tokens.unwrap_err()); Ok(t) => t,
} };
let tokens = tokens.unwrap();
let mut header_clone = self.header.clone(); // we clone as READing is simpler this way let mut header_clone = self.header.clone(); // we clone as READing is simpler this way
let value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens // walk N-1 tokens
if value.is_err() { match EntryHeader::walk_header(&mut header_clone, tokens) {
let e = value.unwrap_err(); Err(e) => match e.err_type() {
return match e.err_type() {
// We cannot find the header key, as there is no path to it // We cannot find the header key, as there is no path to it
SEK::HeaderKeyNotFound => Ok(None), SEK::HeaderKeyNotFound => Ok(None),
_ => Err(e), _ => Err(e),
}; },
Ok(v) => Ok(Some(v.clone())),
} }
Ok(Some(value.unwrap().clone()))
} }
pub fn delete(&mut self, spec: &str) -> Result<Option<Value>> { pub fn delete(&mut self, spec: &str) -> Result<Option<Value>> {