Remove unwrap() calls by matching
This commit is contained in:
parent
0b7f815104
commit
944a9bf876
1 changed files with 13 additions and 15 deletions
|
@ -919,25 +919,23 @@ impl EntryHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&mut self, spec: &str) -> Result<Option<Value>> {
|
pub fn delete(&mut self, spec: &str) -> Result<Option<Value>> {
|
||||||
let tokens = EntryHeader::tokenize(spec, '.');
|
let tokens = match EntryHeader::tokenize(spec, '.') {
|
||||||
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 destination = tokens.iter().last();
|
let destination = match tokens.iter().last() {
|
||||||
if destination.is_none() {
|
None => return Err(SE::new(SEK::HeaderPathSyntaxError, None)),
|
||||||
return Err(SE::new(SEK::HeaderPathSyntaxError, None));
|
Some(d) => d
|
||||||
}
|
};
|
||||||
let destination = destination.unwrap();
|
|
||||||
debug!("destination = {:?}", destination);
|
debug!("destination = {:?}", destination);
|
||||||
|
|
||||||
let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens
|
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
|
// walk N-1 tokens
|
||||||
if value.is_err() {
|
let mut value = match EntryHeader::walk_header(&mut self.header, path_to_dest) {
|
||||||
return Err(value.unwrap_err());
|
Err(e) => return Err(e),
|
||||||
}
|
Ok(v) => v
|
||||||
let mut value = value.unwrap();
|
};
|
||||||
debug!("walked value = {:?}", value);
|
debug!("walked value = {:?}", value);
|
||||||
|
|
||||||
match *destination {
|
match *destination {
|
||||||
|
|
Loading…
Reference in a new issue