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


Rust NonZeroU16.saturating_add用法及代码示例


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

用法

pub const fn saturating_add(self, other: u16) -> NonZeroU16

将无符号整数添加到非零值。溢出时返回 u16::MAX

例子

#![feature(nonzero_ops)]

let one = NonZeroU16::new(1)?;
let two = NonZeroU16::new(2)?;
let max = NonZeroU16::new(u16::MAX)?;

assert_eq!(two, one.saturating_add(1));
assert_eq!(max, max.saturating_add(1));

相关用法


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