Add optional serde support for Rational#22
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.