Tracking issue for core::ops::*<T>
on Saturating<T>
/ Wrapping<T>
type
#91586
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Relevant RFC "928" (rust-lang/rfcs#928).
Saturating
type #87920Public API
The
Wrapping
andSaturating
types enforce that a certain behaviour for all operations on the underlying integer is performed -.wrapping_*
or.saturating_*
. When doing the "simplified" operations,.add
always becomes.wrapping_add
or.saturating_add
,.sub
always becomes.wrapping_sub
/.saturating_sub
and so on.The fundamental ideas seem to be:
.wrapping_*
or.saturating_*
.wrapping_*
or.saturating_*
But number 2 seems to fall short in reality. The traits in
core::ops::
are only implemented forWrapping
andSaturating
where the other type isWrapping
orSaturating
as well (impl core::ops::*<Wrapping<T>> for Wrapping<T>
¹). So, instead of writing a integer addition like this:for
Wrapping
andSaturating
types, it looks likes this:This introduces the need for additional mentions of
Wrapping
/Saturating
in every code location where an integer operation is performed - and in my opinion, adds unnecessary noise to the code. In my opinion, having the integer being wrapped in eitherWrapping
orSaturating
in the declaration / initialization should be all that is needed.I propose that - in addition to
impl core::ops::*<Wrapping<T>> for Wrapping<T>
¹ - the integer operations are also implemented using the raw integer type itself (impl core::ops::*<T> for Wrapping<T>
¹), and therefore the following is being made possible:¹ as well as for
Saturating
Steps / History
Wrapping
type Tracking issue for integer methods for Wrapping #32463Saturating
type Tracking Issue forSaturating
type #87920Wrapping
TBDSaturating
Tracking Issue forsaturating_int_assign_impl
#92354Wrapping
Saturating
Unresolved Questions
Following "The overarching philosophy is: do whatever is easiest", I created this PR because the underlying types already exist, and it "only" proposes additional trait impls. Or does this change need a proper RFC?
The text was updated successfully, but these errors were encountered: