Skip to content

Commit

Permalink
Format f64 in error messages using ryu
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 26, 2024
1 parent 107c2d1 commit 83d7bad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,14 @@ struct JsonUnexpected<'a>(de::Unexpected<'a>);

impl<'a> Display for JsonUnexpected<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if let de::Unexpected::Unit = self.0 {
formatter.write_str("null")
} else {
Display::fmt(&self.0, formatter)
match self.0 {
de::Unexpected::Unit => formatter.write_str("null"),
de::Unexpected::Float(value) => write!(
formatter,
"floating point `{}`",
ryu::Buffer::new().format(value),
),
unexp => Display::fmt(&unexp, formatter),
}
}
}
Expand Down

0 comments on commit 83d7bad

Please sign in to comment.