Struct std::num::NonZeroU128 1.28.0[−][src]
#[repr(transparent)]pub struct NonZeroU128(_);
Expand description
已知不等于零的整数。
这样可以进行一些内存布局优化。
For example, Option<NonZeroU128>
is the same size as u128
:
use std::mem::size_of; assert_eq!(size_of::<Option<core::num::NonZeroU128>>(), size_of::<u128>());Run
Implementations
如果给定值不为零,则创建一个非零值。
返回大于或等于 n 的 2 的最小幂。
如果下一个 2 的幂大于类型的最大值,则检查是否溢出并返回 None
。
因此,结果不能归零。
Examples
#![feature(nonzero_ops)] let two = NonZeroU128::new(2)?; let three = NonZeroU128::new(3)?; let four = NonZeroU128::new(4)?; let max = NonZeroU128::new(u128::MAX)?; assert_eq!(Some(two), two.checked_next_power_of_two() ); assert_eq!(Some(four), three.checked_next_power_of_two() ); assert_eq!(None, max.checked_next_power_of_two() );Run
当且仅当某些 k
的 self == (1 << k)
时,才返回 true
。
在许多体系结构上,此函数可以在基础整数类型上比 is_power_of_two()
更好地执行,因为可以避免对零的特殊处理。
Examples
基本用法:
#![feature(nonzero_is_power_of_two)] let eight = std::num::NonZeroU128::new(8).unwrap(); assert!(eight.is_power_of_two()); let ten = std::num::NonZeroU128::new(10).unwrap(); assert!(!ten.is_power_of_two());Run
Trait Implementations
type Output = NonZeroU128
type Output = NonZeroU128
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroU128
type Output = NonZeroU128
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroU128
type Output = NonZeroU128
应用 |
运算符后的结果类型。
执行 |=
操作。 Read more
执行 |=
操作。 Read more
Converts a NonZeroU128
into an u128
Converts NonZeroU16
to NonZeroU128
losslessly.
Converts NonZeroU32
to NonZeroU128
losslessly.
Converts NonZeroU64
to NonZeroU128
losslessly.
Converts NonZeroU8
to NonZeroU128
losslessly.
type Err = ParseIntError
type Err = ParseIntError
可以从解析中返回的相关错误。
解析字符串 s
以返回此类型的值。 Read more
此方法测试 self
和 other
值是否相等,并由 ==
使用。 Read more
此方法测试 !=
。
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: NonZeroI16
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI16>>::Error>
[src]
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI16>>::Error>
[src]Attempts to convert NonZeroI16
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI32>>::Error>
[src]
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI32>>::Error>
[src]Attempts to convert NonZeroI32
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI64>>::Error>
[src]
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI64>>::Error>
[src]Attempts to convert NonZeroI64
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI8>>::Error>
[src]
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI8>>::Error>
[src]Attempts to convert NonZeroI8
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroU8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroI8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroU64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroIsize
.
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: NonZeroU128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroI64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroI32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroI16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroUsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU128>>::Error>
[src]
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU128>>::Error>
[src]Attempts to convert NonZeroU128
to NonZeroU16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroUsize>>::Error>
[src]
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroUsize>>::Error>
[src]Attempts to convert NonZeroUsize
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert u128
to NonZeroU128
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。