Skip to content

Commit

Permalink
refactor: use Try operator in kv::Visitor (#24)
Browse files Browse the repository at this point in the history
Avoids unwrapping in functions which return a `Result`.

Admittedly this is limitedly useful here because everything is preseently unwrapped at a higher-level anyways but is still good practice.
  • Loading branch information
Fishrock123 authored Dec 4, 2020
1 parent 12e70d8 commit e8593e7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ndjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn format_kv_pairs<'b>(mut out: &mut StdoutLock<'b>, record: &Record) {
key: kv::Key<'kvs>,
val: kv::Value<'kvs>,
) -> Result<(), kv::Error> {
write!(self.string, ",\"{}\":{}", key, val).unwrap();
write!(self.string, ",\"{}\":{}", key, val)?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn format_kv_pairs<'b>(mut out: &mut StdoutLock<'b>, record: &Record) {
key: kv::Key<'kvs>,
val: kv::Value<'kvs>,
) -> Result<(), kv::Error> {
write!(self.stdout, "\n {}{}{} {}", BOLD, key, RESET, val).unwrap();
write!(self.stdout, "\n {}{}{} {}", BOLD, key, RESET, val)?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn format_kv_pairs(record: &Record) -> Option<Object> {
if self.hashmap.is_none() {
self.hashmap = Some(HashMap::new())
}
let hm = self.hashmap.as_mut().unwrap();
let hm = self.hashmap.as_mut()?;
hm.insert(key.to_string(), val.to_string());
Ok(())
}
Expand Down

0 comments on commit e8593e7

Please sign in to comment.