From 604e59ae3cc089b116b6c9a07a56f1895637ce51 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 14 May 2016 19:24:01 +0200 Subject: [PATCH] Remove unwrap() calls by matching --- libimagstore/src/store.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index c124c41e..90a3b54b 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -701,24 +701,23 @@ impl EntryHeader { } pub fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result { - let tokens = EntryHeader::tokenize(spec, sep); - if tokens.is_err() { // return parser error if any - return tokens.map(|_| false); - } - let tokens = tokens.unwrap(); + let tokens = match EntryHeader::tokenize(spec, sep) { + 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, + }; 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 value.map(|_| false); - } - let mut value = value.unwrap(); + + // walk N-1 tokens + let value = match EntryHeader::walk_header(&mut self.header, path_to_dest) { + Err(e) => return Err(e), + Ok(v) => v + }; // There is already an value at this place if EntryHeader::extract(value, destination).is_ok() {