Add number suffixes and allow more number underscores#481
Merged
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #481 +/- ##
==========================================
+ Coverage 82.95% 84.02% +1.07%
==========================================
Files 74 75 +1
Lines 9267 10035 +768
==========================================
+ Hits 7687 8432 +745
- Misses 1580 1603 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
Manually checking the coverage shows that 100% of the patch seems to be covered |
juntyr
commented
Aug 22, 2023
juntyr
commented
Aug 22, 2023
4b4d20a to
c6622b2
Compare
Member
Author
Member
Author
|
One interesting detail for the future is that:
If we don't want this behaviour (in a future where roundtripping through |
torkleyy
approved these changes
Aug 23, 2023
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #241
This PR implements optional number type suffixes, which can be turned on with the
PrettyConfig::number_suffixesoption and are allowed during parsing. To allow Rusty suffixes to work with floating literals, this PR also finally allows using underscores in float literals, using the Rust syntax as a reference.This PR turned out to be significantly more work than I had anticipated. In particular, a number which could fit into the destination type, e.g.
1_u8, now has to reject when deserialising into a typedu16, since the type is an explicit mismatch. I tried my best to keep the changes in parsing small-ish and to use this opportunity to improve some error reporting a bit.For users of RON, this should be an unobservable change (apart from some error code changes which are now more meaningful). However, writing RON files can now be a bit more Rusty as types can be encoded explicitly and underscores can be used to make (long) number literals more readable. However, anyone serialising RON data should probably not turn the
PrettyConfig::number_suffixesflag on unless they need lossless roundtrips throughValue::Numbervariants, since explicit typing makes it harder to upgrade a format to different number types without breaking compatibility.CHANGELOG.md