-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add method for computing the difference of two unsigned integers in a signed #381
Comments
Given that we have https://doc.rust-lang.org/std/primitive.u32.html#method.checked_add_signed and friends now, it does seem plausible to have something like this. Naming it is hard, though -- it's like |
A little off topic, but that does remind me, is there a reason why |
For most cases
I'd prefer one of |
We discussed this in the libs-api meeting today. We think there is a good case for having this function in the standard library, however we prefer the following signature instead: impl Unsigned {
fn checked_signed_diff(self, other: Unsigned) -> Option<Signed>;
} We are accepting the ACP with this modified signature. |
It would also make sense then to have impl Signed {
fn checked_unsigned_diff(...)
} in the implementation PR, for fullness |
Proposal
Problem statement
Motivating examples or use cases
Solution sketch
Benchmarking
https://godbolt.org/z/dxrP4d9vT
Implementation
https://github.com/davidzeng0/xx-core/blob/main/src/impls/uint.rs#L12
Links and related work
rust-lang/rust#117476
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: