-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.
Description
This is an issue in need of a PR to modify RFC #560 (text)
During the course of my work attempting to land the integer overflow checking PRs (see rust-lang/rust#22532), I identified some simple types that we should consider adding to the stdlib.
- The RFC documents
WrappingOps
Wrapping<N>
, which just marks the type as following the usual arithmetic modulo bitwidth rules. (So this is sort of built-in already, not a new change.) - In addition, I added
OverflowingOps
, which provides methods for e.g.overflowing_add(self, Self) -> (Self, bool)
, where the returned boolean is a flag indicating whether overflow occurred. This was quite useful for composing certain functions where knowledge of overflow was needed. (i am not sure if aOverflowing<N>
trait is warranted.) - We probably also want
SaturatingOps
andSaturating<N>
. (I think we already have the methods for the former; so that is just a question of whether the ops need their its own trait. But I think `Saturating is justified either way.) - I think we may want some form of support for
impl Add<N> for Result<N, Overflow>>
where the result type isResult<N, Overflow>
(andOverflow
is a zero-sized struct). At least, I think this would enable patterns of composition likelet value: N = try!(a + b - c + d);
- ---- (adding more ideas below this line) ----
- Atomic numeric types probably need to be addressed in some way as well; see discussion here: Implement arithmetic overflow changes rust#20795 (comment)
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.