Struct std::num::NonZeroI128 1.34.0[−][src]
#[repr(transparent)]pub struct NonZeroI128(_);
Expand description
已知不等于零的整数。
这样可以进行一些内存布局优化。
For example, Option<NonZeroI128>
is the same size as i128
:
use std::mem::size_of; assert_eq!(size_of::<Option<core::num::NonZeroI128>>(), size_of::<i128>());Run
Implementations
如果给定值不为零,则创建一个非零值。
计算 self 的绝对值,带有溢出信息,请参见
Example
#![feature(nonzero_ops)] let pos = NonZeroI128::new(1)?; let neg = NonZeroI128::new(-1)?; let min = NonZeroI128::new(i128::MIN)?; assert_eq!((pos, false), pos.overflowing_abs()); assert_eq!((pos, false), neg.overflowing_abs()); assert_eq!((min, true), min.overflowing_abs());Run
饱和绝对值,请参见
i128::saturating_abs
.
Example
#![feature(nonzero_ops)] let pos = NonZeroI128::new(1)?; let neg = NonZeroI128::new(-1)?; let min = NonZeroI128::new(i128::MIN)?; let min_plus = NonZeroI128::new(i128::MIN + 1)?; let max = NonZeroI128::new(i128::MAX)?; assert_eq!(pos, pos.saturating_abs()); assert_eq!(pos, neg.saturating_abs()); assert_eq!(max, min.saturating_abs()); assert_eq!(max, min_plus.saturating_abs());Run
包装绝对值,请参见
i128::wrapping_abs
.
Example
#![feature(nonzero_ops)] let pos = NonZeroI128::new(1)?; let neg = NonZeroI128::new(-1)?; let min = NonZeroI128::new(i128::MIN)?; let max = NonZeroI128::new(i128::MAX)?; assert_eq!(pos, pos.wrapping_abs()); assert_eq!(pos, neg.wrapping_abs()); assert_eq!(min, min.wrapping_abs());Run
在没有任何包装或 panicking 的情况下计算 self 的绝对值。
Example
#![feature(nonzero_ops)] let u_pos = NonZeroU128::new(1)?; let i_pos = NonZeroI128::new(1)?; let i_neg = NonZeroI128::new(-1)?; let i_min = NonZeroI128::new(i128::MIN)?; let u_max = NonZeroU128::new(u128::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());Run
Trait Implementations
type Output = NonZeroI128
type Output = NonZeroI128
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroI128
type Output = NonZeroI128
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroI128
type Output = NonZeroI128
应用 |
运算符后的结果类型。
执行 |=
操作。 Read more
执行 |=
操作。 Read more
Converts a NonZeroI128
into an i128
Converts NonZeroI16
to NonZeroI128
losslessly.
Converts NonZeroI32
to NonZeroI128
losslessly.
Converts NonZeroI64
to NonZeroI128
losslessly.
Converts NonZeroI8
to NonZeroI128
losslessly.
Converts NonZeroU16
to NonZeroI128
losslessly.
Converts NonZeroU32
to NonZeroI128
losslessly.
Converts NonZeroU64
to NonZeroI128
losslessly.
Converts NonZeroU8
to NonZeroI128
losslessly.
type Err = ParseIntError
type Err = ParseIntError
可以从解析中返回的相关错误。
解析字符串 s
以返回此类型的值。 Read more
此方法测试 self
和 other
值是否相等,并由 ==
使用。 Read more
此方法测试 !=
。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroUsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroI32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroI16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroU8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroU16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroI8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroU64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroI128>>::Error>
[src]
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroI128>>::Error>
[src]Attempts to convert NonZeroI128
to NonZeroI64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroI128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroI128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroUsize>>::Error>
[src]
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroUsize>>::Error>
[src]Attempts to convert NonZeroUsize
to NonZeroI128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert i128
to NonZeroI128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。