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


Rust NonZeroU8.saturating_add用法及代码示例


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

用法

pub const fn saturating_add(self, other: u8) -> NonZeroU8

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

例子

#![feature(nonzero_ops)]

let one = NonZeroU8::new(1)?;
let two = NonZeroU8::new(2)?;
let max = NonZeroU8::new(u8::MAX)?;

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

相关用法


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