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


Rust NonZeroI32.abs用法及代码示例


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

用法

pub const fn abs(self) -> NonZeroI32

计算 self 的绝对值。有关溢出行为的文档,请参阅 i32::abs

示例

#![feature(nonzero_ops)]

let pos = NonZeroI32::new(1)?;
let neg = NonZeroI32::new(-1)?;

assert_eq!(pos, pos.abs());
assert_eq!(pos, neg.abs());

相关用法


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