@@ -56,6 +56,10 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
5656 /// wrapped in Some.
5757 fn checked_next_power_of_two ( self ) -> Option < Self > ;
5858
59+ /// Checked subtraction with a signed integer. Computes `self - rhs`,
60+ /// returning `None` if overflow occurred.
61+ fn checked_sub_signed ( self , rhs : Self :: Signed ) -> Option < Self > ;
62+
5963 /// Calculates the quotient of `self` and rhs, rounding the result towards positive infinity.
6064 fn div_ceil ( self , rhs : Self ) -> Self ;
6165
@@ -75,13 +79,25 @@ pub trait PrimitiveUnsigned: PrimitiveInteger + From<u8> {
7579 /// boolean indicating whether an arithmetic overflow would occur.
7680 fn overflowing_add_signed ( self , rhs : Self :: Signed ) -> ( Self , bool ) ;
7781
82+ /// Calculates `self` - `rhs` with a signed `rhs`. Returns a tuple of the subtraction along
83+ /// with a boolean indicating whether an arithmetic overflow would occur.
84+ fn overflowing_sub_signed ( self , rhs : Self :: Signed ) -> ( Self , bool ) ;
85+
7886 /// Saturating addition with a signed integer. Computes `self + rhs`, saturating at the numeric
7987 /// bounds instead of overflowing.
8088 fn saturating_add_signed ( self , rhs : Self :: Signed ) -> Self ;
8189
90+ /// Saturating integer subtraction. Computes `self` - `rhs`, saturating at
91+ /// the numeric bounds instead of overflowing.
92+ fn saturating_sub_signed ( self , rhs : Self :: Signed ) -> Self ;
93+
8294 /// Wrapping (modular) addition with a signed integer. Computes `self + rhs`, wrapping around
8395 /// at the boundary of the type.
8496 fn wrapping_add_signed ( self , rhs : Self :: Signed ) -> Self ;
97+
98+ /// Wrapping (modular) subtraction with a signed integer. Computes
99+ /// `self - rhs`, wrapping around at the boundary of the type.
100+ fn wrapping_sub_signed ( self , rhs : Self :: Signed ) -> Self ;
85101}
86102
87103/// Trait for references to primitive unsigned integer types ([`PrimitiveUnsigned`]).
@@ -101,14 +117,18 @@ macro_rules! impl_unsigned {
101117 fn checked_add_signed( self , rhs: Self :: Signed ) -> Option <Self >;
102118 fn checked_next_multiple_of( self , rhs: Self ) -> Option <Self >;
103119 fn checked_next_power_of_two( self ) -> Option <Self >;
120+ fn checked_sub_signed( self , rhs: Self :: Signed ) -> Option <Self >;
104121 fn div_ceil( self , rhs: Self ) -> Self ;
105122 fn is_multiple_of( self , rhs: Self ) -> bool ;
106123 fn is_power_of_two( self ) -> bool ;
107124 fn next_multiple_of( self , rhs: Self ) -> Self ;
108125 fn next_power_of_two( self ) -> Self ;
109126 fn overflowing_add_signed( self , rhs: Self :: Signed ) -> ( Self , bool ) ;
127+ fn overflowing_sub_signed( self , rhs: Self :: Signed ) -> ( Self , bool ) ;
110128 fn saturating_add_signed( self , rhs: Self :: Signed ) -> Self ;
129+ fn saturating_sub_signed( self , rhs: Self :: Signed ) -> Self ;
111130 fn wrapping_add_signed( self , rhs: Self :: Signed ) -> Self ;
131+ fn wrapping_sub_signed( self , rhs: Self :: Signed ) -> Self ;
112132 }
113133 }
114134
0 commit comments