@@ -679,6 +679,36 @@ macro_rules! nonzero_unsigned_signed_operations {
679
679
None
680
680
}
681
681
}
682
+
683
+ /// Multiply two non-zero integers together.
684
+ #[ doc = concat!( "Return [`" , stringify!( $Int) , "::MAX`] on overflow." ) ]
685
+ ///
686
+ /// # Examples
687
+ ///
688
+ /// ```
689
+ /// #![feature(nonzero_ops)]
690
+ /// # #![feature(try_trait)]
691
+ #[ doc = concat!( "# use std::num::" , stringify!( $Ty) , ";" ) ]
692
+ ///
693
+ /// # fn main() -> Result<(), std::option::NoneError> {
694
+ #[ doc = concat!( "let two = " , stringify!( $Ty) , "::new(2)?;" ) ]
695
+ #[ doc = concat!( "let four = " , stringify!( $Ty) , "::new(4)?;" ) ]
696
+ #[ doc = concat!( "let max = " , stringify!( $Ty) , "::new(" ,
697
+ stringify!( $Int) , "::MAX)?;" ) ]
698
+ ///
699
+ /// assert_eq!(four, two.saturating_mul(two));
700
+ /// assert_eq!(max, four.saturating_mul(max));
701
+ /// # Ok(())
702
+ /// # }
703
+ /// ```
704
+ #[ unstable( feature = "nonzero_ops" , issue = "84186" ) ]
705
+ #[ inline]
706
+ pub const fn saturating_mul( self , other: $Ty) -> $Ty {
707
+ // SAFETY: saturating_mul returns u*::MAX on overflow
708
+ // and `other` is also non-null
709
+ // so the result cannot be zero.
710
+ unsafe { $Ty:: new_unchecked( self . get( ) . saturating_mul( other. get( ) ) ) }
711
+ }
682
712
}
683
713
) +
684
714
}
0 commit comments