From 944a9bf876f8a9dcdae112c59b0db0f67e61a849 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 14 May 2016 19:33:41 +0200 Subject: [PATCH] Remove unwrap() calls by matching --- libimagstore/src/store.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 73da21ba..573efb82 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -919,25 +919,23 @@ impl EntryHeader { } pub fn delete(&mut self, spec: &str) -> Result> { - let tokens = EntryHeader::tokenize(spec, '.'); - if tokens.is_err() { // return parser error if any - return Err(tokens.unwrap_err()); - } - let tokens = tokens.unwrap(); + let tokens = match EntryHeader::tokenize(spec, '.') { + Err(e) => return Err(e), + Ok(t) => t + }; - let destination = tokens.iter().last(); - if destination.is_none() { - return Err(SE::new(SEK::HeaderPathSyntaxError, None)); - } - let destination = destination.unwrap(); + let destination = match tokens.iter().last() { + None => return Err(SE::new(SEK::HeaderPathSyntaxError, None)), + Some(d) => d + }; debug!("destination = {:?}", destination); let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens - let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens - if value.is_err() { - return Err(value.unwrap_err()); - } - let mut value = value.unwrap(); + // walk N-1 tokens + let mut value = match EntryHeader::walk_header(&mut self.header, path_to_dest) { + Err(e) => return Err(e), + Ok(v) => v + }; debug!("walked value = {:?}", value); match *destination {