Struct core::num::NonZeroU32 1.28.0[−][src]
#[repr(transparent)]pub struct NonZeroU32(_);
Expand description
已知不等于零的整数。
这样可以进行一些内存布局优化。
For example, Option<NonZeroU32>
is the same size as u32
:
use std::mem::size_of;
assert_eq!(size_of::<Option<core::num::NonZeroU32>>(), size_of::<u32>());
RunImplementations
返回大于或等于 n 的 2 的最小幂。
如果下一个 2 的幂大于类型的最大值,则检查是否溢出并返回 None
。
因此,结果不能归零。
Examples
#![feature(nonzero_ops)]
let two = NonZeroU32::new(2)?;
let three = NonZeroU32::new(3)?;
let four = NonZeroU32::new(4)?;
let max = NonZeroU32::new(u32::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() );
RunTrait Implementations
type Output = NonZeroU32
type Output = NonZeroU32
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
执行 |=
操作。 Read more
执行 |=
操作。 Read more
Converts NonZeroU16
to NonZeroU32
losslessly.
Converts a NonZeroU32
into an u32
Converts NonZeroU32
to NonZeroU64
losslessly.
Converts NonZeroU32
to NonZeroU128
losslessly.
Converts NonZeroU32
to NonZeroI64
losslessly.
Converts NonZeroU32
to NonZeroI128
losslessly.
此方法测试 self
和 other
值是否相等,并由 ==
使用。 Read more
此方法测试 !=
。
如果存在,则此方法返回 self
和 other
值之间的顺序。 Read more
Attempts to convert NonZeroI128
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroI16
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroI32
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroI64
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroIsize
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU128
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroU8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroU16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroUsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroI8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroI16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroI32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU32
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroU64
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
Attempts to convert NonZeroUsize
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。