当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust NonZeroI32.saturating_mul用法及代码示例


本文简要介绍rust语言中 std::num::NonZeroI32.saturating_mul 的用法。

用法

pub const fn saturating_mul(self, other: NonZeroI32) -> NonZeroI32

将两个非零整数相乘。溢出时返回 i32::MAX

例子

#![feature(nonzero_ops)]

let two = NonZeroI32::new(2)?;
let four = NonZeroI32::new(4)?;
let max = NonZeroI32::new(i32::MAX)?;

assert_eq!(four, two.saturating_mul(two));
assert_eq!(max, four.saturating_mul(max));

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::num::NonZeroI32.saturating_mul。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。