Currently we have i32::wrapping_add, i32::wrapping_sub, i32::wrapping_div etc bound to i32, that is, there is no trait for them. We also have Wrapping<T>, and an impl for each number type. (source)
I want this to be changed, so that we instead have WrappingAdd which defines wrapping_add(self, RHS) -> Self::Output, WrappingSub which defines wrapping_sub(self, RHS) -> Self::Output and so on, and Wrapping<T> which uses them. This would hopefully simplify the language, and it would also be possible to create Wrapping<T>-compatible types. (You can't impl stuff for Wrapping currently.)
They would probably be placed in std::num.
(Side note: If it goes into std::ops we could also have wrapping ops in the form of |+|, |-|, etc.)
Can we leave the creep for operators within inferior languages like swift? With wrapping_add I have something I can search for in google etc, but |+| isn't compatible with how google built its index.
Uh, yeah, sure. I don't mind using Wrapping<T>. Just wish it wasn't so hardcoded.
@est31 , please don't refer to other languages as inherently inferior.
I will only reply shortly (even if this seems like a lot of text, I could write more on it), because discussing this further will get us way off-topic: I just expressed what I feel. I don't know swift really so I don't know whether its inherently inferior or not. Yes, everything has its upsides and downsides, and probably you have far more knowledge about Rust and Swift and can make a far more nuanced comparison. But I consider a small set of operators a feature, not something that must be extended, and this particular aspect of swift not well-thought. Perhaps my view is clouded due to preference, but I doubt that language success or ease to write in depends on how many operators it contains.
Note that for my limited POV, Swift _is_ inferior. For people who want to program IOS apps, Swift may be not inferior, but Rust may be. I do accept that not everybody shares the same opinion, feelings, or view on a topic, and I hope you do, too.
@SoniEx2 You changed the title of this issue to mention specific traits, but actually the issue is more general, right? In particular, we should also do the same for rotate_left() and rotate_right(), right? Or, is there some reason that should be put in another issue?
@briansmith That's what the "etc" part of the title is for. Everything in https://static.rust-lang.org/doc/master/std/num/struct.Wrapping.html that isn't a blanket implementation (i.e. everything that doesn't have where T: ...) should have a corresponding WrappingWhatever trait.
Most helpful comment
@est31 , please don't refer to other languages as inherently inferior.