num-integer
num-integer copied to clipboard
Increment and decrement methods for Integer trait?
From @L117 on June 22, 2017 9:55
When dealing with primitive integers it's fast and easy to increment/decrement with x += 1;/x -= 1;, but with BigInt/BigUint it wastes an allocation and/or becomes tedious (Imagine calling One::one, From::from and defining static ONE). So such methods could come in handy.
Copied from original issue: rust-num/num#307
Sure, that could be useful.
The trait will have to provide default implementations in order for this to not be a breaking change, which means it probably has to require Clone. e.g. *self = self.clone() + Self::one(). But that's harmless for primitives and can be overridden in types like the bigints.
this would be really handy
I've just discovered the Step trait.
the Integer trait could simply delegate to Step, or Step could be added as a bound for the Integer trait.
as in-
pub trait Integer: Step {
...
}
or users can just use the Step trait directly...
It would be a breaking change for Integer to require Step, and also that trait is still unstable.
Closed by #53