-
Notifications
You must be signed in to change notification settings - Fork 149
impl remaining num-traits for std::num::Wrapping<T> #286
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
I'm with you on The We need tests for the stuff you're adding too. (I should have asked for that on the |
Got it - I'll rollback PrimInt, Checked and Saturating, remove inline hints and add tests. In the meantime, I'd like to understand what you meant by "treating Wrapped in a way that's not supported by the standard library" - AFAIK the doc only says that "all standard arithmetic operations on the underlying value are intended to have wrapping semantics" and I don't see how that would be incompatible with PrimInt, Checked* and Saturating*. Would you mind elaborating a bit ? I don't intend to argue. About the tests, I'll give them a honest try, looking at what's already there, but if you have specific expectations in the meantime I'd be happy to hear them. |
It's OK to argue a little -- if I'm wrong, someone should convince me of the right way. :) To me, the problem is that the standard Yes, this means you can't pass a
I had no particular expectations beyond trying to exercise to code in some way at all. If we don't even try it, we could find that we were missing some conditional trait bounds that made them ineffective, for example. |
I see your point, and I'm fine with this since the point of this PR is merely to make If you are fine with the tests (which I can't tell are overdone or not enough), I think this is ready to be merged. And just for future discussion on the matter, here's my opinion the unimplemented traits :
|
This looks very nice, thanks! @homu r+ |
📌 Commit 9115df6 has been approved by |
impl remaining num-traits for std::num::Wrapping<T> This is a (late) follow-up for [https://github.com/rust-num/num/pull/279](https://github.com/rust-num/num/pull/279) since I realized that implementing `Num` for `Wrapping<T>` was merely half of the work. This PR makes `Wrapping<T>` implement the remaining appropriate traits, granting it the ability to really be used a complete substitute for its primitive integer counterparts. Some benefits are : - Less refactoring for users using `num`'s traits replacing some primitives by their `Wrapping` counterpart (same for the opposite); - Since `Wrapping<T>` is from `std`, nobody except us can `impl` our traits for it, so people don't have to create their own.
☀️ Test successful - status |
This is a (late) follow-up for #279 since I realized that implementing
Num
forWrapping<T>
was merely half of the work.This PR makes
Wrapping<T>
implement the remaining appropriate traits, granting it the ability to really be used a complete substitute for its primitive integer counterparts.Some benefits are :
num
's traits replacing some primitives by theirWrapping
counterpart (same for the opposite);Wrapping<T>
is fromstd
, nobody except us canimpl
our traits for it, so people don't have to create their own.