Skip to content

Commit

Permalink
Utilize better error conversion from log
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Jul 8, 2019
1 parent 2c6d7dd commit fb5d203
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Default for Builder {

impl Builder {
/// Convert the format into a callable function.
///
///
/// If the `custom_format` is `Some`, then any `default_format` switches are ignored.
/// If the `custom_format` is `None`, then a default format is returned.
/// Any `default_format` switches set to `false` won't be written by the format.
Expand Down Expand Up @@ -177,7 +177,7 @@ type SubtleStyle = StyledValue<'static, &'static str>;
type SubtleStyle = &'static str;

/// The default format.
///
///
/// This format needs to work with any combination of crate features.
struct DefaultFormat<'a> {
timestamp: bool,
Expand Down Expand Up @@ -305,16 +305,15 @@ impl<'a> DefaultFormat<'a> {
let open_brace = self.subtle_style("[");
write!(self.buf, "{}", open_brace)?;
}
// Ideally we would be able to transport the original io::Error through the visit
kvs.visit(&mut KeyValueVisitor(self.buf)).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
kvs.visit(&mut KeyValueVisitor(self.buf)).map_err(|e| e.into())
}
}

struct KeyValueVisitor<'a>(&'a mut Formatter);

impl<'a, 'kvs> kv::Visitor<'kvs> for KeyValueVisitor<'a> {
fn visit_pair(&mut self, key: kv::Key<'kvs>, value: kv::Value<'kvs>) -> Result<(), kv::Error> {
write!(self.0, " {}={}", key, value).map_err(|_| kv::Error::msg("printing failed"))
write!(self.0, " {}={}", key, value).map_err(|e| e.into())
}
}

Expand Down

0 comments on commit fb5d203

Please sign in to comment.