-
Notifications
You must be signed in to change notification settings - Fork 2
Add optional serde support for Rational
#22
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
Conversation
we're doing this because some formats such as `toml` decided to not support i128
|
Thanks for your PR! Would you mind adding a few unit tests? (De)serializing an integer, a non-integer, and very small/large values would be nice to see. |
|
Sure, I added some unit tests. |
|
Great, thank you! As I mentioned in the issue you posted, I have some qualms about changing the serialization behavior based on the value of the rational. It would seem surprising to me as a user of the library if We could still support deserializing from both integers and strings however, that seems like a reasonable feature to include. |
|
I changed it so that it always serializes as a string.
No, that's just serde_json being stupid in handling very big numbers. Which, given how loosely json defines what a "number" is, maybe shouldn't be surprising. But as I wrote, using |
|
Gotcha. Anyways, thanks for the contribution, I'll merge this and release it in a sec. |
|
Released version 1.7.0 |
This PR allows (de)serializing rationals using serde. If the rational is representable as an integer, we serialize it as such, otherwise as a string displaying the fraction.