Format f64 in error messages using ryu

This commit is contained in:
David Tolnay 2024-01-26 13:14:48 -08:00
parent 107c2d1c42
commit 83d7bad54b
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -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),
}
}
}