num-integer icon indicating copy to clipboard operation
num-integer copied to clipboard

Increment and decrement methods for Integer trait?

Open cuviper opened this issue 7 years ago • 4 comments

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

cuviper avatar Dec 19 '17 19:12 cuviper

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.

cuviper avatar Dec 19 '17 19:12 cuviper

this would be really handy

danieleades avatar Jan 10 '21 18:01 danieleades

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...

danieleades avatar Jan 12 '21 09:01 danieleades

It would be a breaking change for Integer to require Step, and also that trait is still unstable.

cuviper avatar Jan 12 '21 19:01 cuviper

Closed by #53

cuviper avatar Feb 08 '24 01:02 cuviper