本文簡要介紹rust語言中 core::num::NonZeroI32.unsigned_abs
的用法。
用法
pub const fn unsigned_abs(self) -> NonZeroU32
計算 self 的絕對值,沒有任何包裝或Panics。
示例
#![feature(nonzero_ops)]
let u_pos = NonZeroU32::new(1)?;
let i_pos = NonZeroI32::new(1)?;
let i_neg = NonZeroI32::new(-1)?;
let i_min = NonZeroI32::new(i32::MIN)?;
let u_max = NonZeroU32::new(u32::MAX / 2 + 1)?;
assert_eq!(u_pos, i_pos.unsigned_abs());
assert_eq!(u_pos, i_neg.unsigned_abs());
assert_eq!(u_max, i_min.unsigned_abs());
相關用法
- Rust NonZeroI32.unchecked_mul用法及代碼示例
- Rust NonZeroI32.trailing_zeros用法及代碼示例
- Rust NonZeroI32.abs用法及代碼示例
- Rust NonZeroI32.checked_mul用法及代碼示例
- Rust NonZeroI32.checked_abs用法及代碼示例
- Rust NonZeroI32.wrapping_abs用法及代碼示例
- Rust NonZeroI32.saturating_abs用法及代碼示例
- Rust NonZeroI32.saturating_pow用法及代碼示例
- Rust NonZeroI32.leading_zeros用法及代碼示例
- Rust NonZeroI32.saturating_mul用法及代碼示例
- Rust NonZeroI32.checked_pow用法及代碼示例
- Rust NonZeroI32.overflowing_abs用法及代碼示例
- Rust NonZeroI32用法及代碼示例
- Rust NonZeroI128.saturating_pow用法及代碼示例
- Rust NonZeroI64.wrapping_abs用法及代碼示例
- Rust NonZeroI8.saturating_pow用法及代碼示例
- Rust NonZeroIsize.wrapping_abs用法及代碼示例
- Rust NonZeroI16.saturating_abs用法及代碼示例
- Rust NonZeroI16.leading_zeros用法及代碼示例
- Rust NonZeroI8.unchecked_mul用法及代碼示例
- Rust NonZeroIsize.checked_mul用法及代碼示例
- Rust NonZeroI64.saturating_pow用法及代碼示例
- Rust NonZeroI128.abs用法及代碼示例
- Rust NonZeroI16.trailing_zeros用法及代碼示例
- Rust NonZeroIsize.checked_abs用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 core::num::NonZeroI32.unsigned_abs。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。