rust-lang / libs-team

The home of the library team
Apache License 2.0
110 stars 18 forks source link

mixed_integer_ops extension #386

Closed davidzeng0 closed 1 month ago

davidzeng0 commented 1 month ago

Proposal

Problem statement

Extend the methods added by https://github.com/rust-lang/rust/issues/87840

https://github.com/rust-lang/libs-team/issues/381#issuecomment-2130783890

The following subtraction methods are missing

impl uX {
    pub const fn checked_sub_signed(self, iX) -> Option<Self>;
    pub const fn overflowing_sub_signed(self, iX) -> (Self, bool);
    pub const fn saturating_sub_signed(self, iX) -> Self;
    pub const fn wrapping_sub_signed(self, iX) -> Self;
}

Motivating examples or use cases

The current best way to replicate checked_sub_signed is by

match signed.checked_neg() {
    Some(neg) => unsigned.checked_add_signed(neg),
    None => unsigned.checked_add(signed as Unsigned)
}

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:

joshtriplett commented 1 month ago

We reviewed these in today's @rust-lang/libs-api meeting, and approved them.