Remove unwrap() calls by matching
This commit is contained in:
parent
2a6e4c62fe
commit
604e59ae3c
1 changed files with 14 additions and 15 deletions
|
@ -701,24 +701,23 @@ impl EntryHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<bool> {
|
pub fn insert_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<bool> {
|
||||||
let tokens = EntryHeader::tokenize(spec, sep);
|
let tokens = match EntryHeader::tokenize(spec, sep) {
|
||||||
if tokens.is_err() { // return parser error if any
|
Err(e) => return Err(e),
|
||||||
return tokens.map(|_| false);
|
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();
|
|
||||||
|
|
||||||
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
|
|
||||||
if value.is_err() {
|
// walk N-1 tokens
|
||||||
return value.map(|_| false);
|
let value = match EntryHeader::walk_header(&mut self.header, path_to_dest) {
|
||||||
}
|
Err(e) => return Err(e),
|
||||||
let mut value = value.unwrap();
|
Ok(v) => v
|
||||||
|
};
|
||||||
|
|
||||||
// There is already an value at this place
|
// There is already an value at this place
|
||||||
if EntryHeader::extract(value, destination).is_ok() {
|
if EntryHeader::extract(value, destination).is_ok() {
|
||||||
|
|
Loading…
Reference in a new issue