Skip to content

Commit

Permalink
Merge pull request #1107 from serde-rs/unexpectedfloat
Browse files Browse the repository at this point in the history
Format f64 in error messages using ryu
  • Loading branch information
dtolnay committed Jan 26, 2024
2 parents 107c2d1 + 83d7bad commit 6a6d2bb
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 6a6d2bb

Please sign in to comment.