Remove unwrap() calls by matching
This commit is contained in:
parent
604e59ae3c
commit
81810dbcc8
1 changed files with 13 additions and 15 deletions
|
@ -796,26 +796,24 @@ impl EntryHeader {
|
|||
}
|
||||
|
||||
pub fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result<Option<Value>> {
|
||||
let tokens = EntryHeader::tokenize(spec, sep);
|
||||
if tokens.is_err() { // return parser error if any
|
||||
return Err(tokens.unwrap_err());
|
||||
}
|
||||
let tokens = tokens.unwrap();
|
||||
let tokens = match EntryHeader::tokenize(spec, sep) {
|
||||
Err(e) => return Err(e),
|
||||
Ok(t) => t,
|
||||
};
|
||||
debug!("tokens = {:?}", tokens);
|
||||
|
||||
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 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 {
|
||||
|
|
Loading…
Reference in a new issue