- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Implement Ser+De for Saturating<T> #2709
Conversation
|
I've added the rustversion crate to version-gate the implementation so that it also compiles for older Rust versions. |
We do version detection in build.rs: Line 64 in 74d0670
|
(also once done, please rebase and squash your commits) |
Done. Thanks for the clarifications! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good.
One question I think we should consider below.
I think it would help to understand more about your use case where these impls are going to be needed.
I'm making a game for a virtual 16 bit architecture with number semantics that saturate at |
@oli-obk I have updated the deserialization code so that it maps exceedingly large or small values to the I will squash and rebase (if needed) after I have an updated approval from you. Thanks! |
@oli-obk I have incorporated your requests and suggestions and squashed everything into one commit |
The serialization implementation is heavily inspired by the existing trait implentation for `std::num::Wrapping<T>`. The deserializing implementation maps input values that lie outside of the numerical range of the output type to the `MIN` or `MAX` value of the output type, depending on the sign of the input value. This behaviour follows to the `Saturating` semantics of the output type. fix serde-rs#2708
Thanks! |
Thanks — published in serde 1.0.198. |
This implementation is heavily inspired by the existing trait implentation for
std::num::Wrapping<T>
.fix #2708