Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format f64 in error messages using ryu #1107

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Comment on lines +469 to +476
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would be good to add a comment why Float is processed differently to reduce count of WTF/min from readers

}
}
}
Expand Down