You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Shouldn't Num be also implemented for std::num::Wrapping<T> ? #278
That would be convenient - I'd like to be able to pass a std::num::Wrapping<T> to anything that accepts a Num type.
Part of the discussion on #175 went over this, so I'd like to share my current use case for such a thing :
I've experimented with a custom "marker" trait named Deterministic which is implemented on types on which basic operations are guaranteed to be consistent across platforms, build settings, etc.
std::num::Wrapping<T> implements Deterministic;
fixed-point numbers are good candidates;
primitive integer types aren't, because they might cause panics when they overflow;
floating-point number types certainly aren't.
With this, I'd like to write functions which only accept types that are both Num and Deterministic (for some kind of reproducible game state data), and I can't pass Wrapping<T>s on them - the only workarounds are either to redefine my own Wrapping type and have it implement Num, or define my own Num trait and... well, in short, nothing very appealing.
This "problem" is easy to solve from within this crate, but it seems more like a matter of agreeing on what the Num trait actually means. As far as I'm concerned, this crate should make Wrapping<T> implement Num.
Thoughts ?
It still feels a little weird to me for Num to permit silent overflow behavior, but I guess it's up to the user of they want that. Plus it's not something we can forbid anyway, as one can always write their own wrapping type like you mentioned. So, OK. Care to send a PR?
Yup! See #279.
To add to the discussion, Numdoes already permit silent overflow behaviour to some extent, because (if I'm not mistaken) primitive integer types are allowed to overflow on release builds. My 2 cents.
Activity
cuviper commentedon Apr 21, 2017
It still feels a little weird to me for
Numto permit silent overflow behavior, but I guess it's up to the user of they want that. Plus it's not something we can forbid anyway, as one can always write their own wrapping type like you mentioned. So, OK. Care to send a PR?yoanlcq commentedon Apr 21, 2017
Yup! See #279.
To add to the discussion,
Numdoes already permit silent overflow behaviour to some extent, because (if I'm not mistaken) primitive integer types are allowed to overflow on release builds. My 2 cents.Auto merge of #279 - yoanlcq:impl-num-for-wrapping, r=cuviper
cuviper commentedon Apr 21, 2017
Fixed by #279.
Merge pull request rust-num#278 from serde-rs/error