Skip to content
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

Increment and decrement methods for Integer trait? #2

Closed
cuviper opened this issue Dec 19, 2017 · 5 comments
Closed

Increment and decrement methods for Integer trait? #2

cuviper opened this issue Dec 19, 2017 · 5 comments

Comments

@cuviper
Copy link
Member

cuviper commented Dec 19, 2017

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
Copy link
Member Author

cuviper commented Dec 19, 2017

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.

@danieleades
Copy link

this would be really handy

@danieleades
Copy link

danieleades commented Jan 12, 2021

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

@cuviper
Copy link
Member Author

cuviper commented Jan 12, 2021

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

@cuviper
Copy link
Member Author

cuviper commented Feb 8, 2024

Closed by #53

@cuviper cuviper closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants