Struct std::num::NonZeroIsize 1.34.0[−][src]
#[repr(transparent)]pub struct NonZeroIsize(_);
Expand description
已知不等于零的整数。
这样可以进行一些内存布局优化。
For example, Option<NonZeroIsize>
is the same size as isize
:
use std::mem::size_of; assert_eq!(size_of::<Option<core::num::NonZeroIsize>>(), size_of::<isize>());Run
Implementations
如果给定值不为零,则创建一个非零值。
计算 self 的绝对值。
See isize::abs
有关溢出行为的文档。
Example
#![feature(nonzero_ops)] let pos = NonZeroIsize::new(1)?; let neg = NonZeroIsize::new(-1)?; assert_eq!(pos, pos.abs()); assert_eq!(pos, neg.abs());Run
计算 self 的绝对值,带有溢出信息,请参见
Example
#![feature(nonzero_ops)] let pos = NonZeroIsize::new(1)?; let neg = NonZeroIsize::new(-1)?; let min = NonZeroIsize::new(isize::MIN)?; assert_eq!((pos, false), pos.overflowing_abs()); assert_eq!((pos, false), neg.overflowing_abs()); assert_eq!((min, true), min.overflowing_abs());Run
饱和绝对值,请参见
isize::saturating_abs
.
Example
#![feature(nonzero_ops)] let pos = NonZeroIsize::new(1)?; let neg = NonZeroIsize::new(-1)?; let min = NonZeroIsize::new(isize::MIN)?; let min_plus = NonZeroIsize::new(isize::MIN + 1)?; let max = NonZeroIsize::new(isize::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
包装绝对值,请参见
isize::wrapping_abs
.
Example
#![feature(nonzero_ops)] let pos = NonZeroIsize::new(1)?; let neg = NonZeroIsize::new(-1)?; let min = NonZeroIsize::new(isize::MIN)?; let max = NonZeroIsize::new(isize::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 = NonZeroUsize::new(1)?; let i_pos = NonZeroIsize::new(1)?; let i_neg = NonZeroIsize::new(-1)?; let i_min = NonZeroIsize::new(isize::MIN)?; let u_max = NonZeroUsize::new(usize::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
将两个非零整数相乘。
Return isize::MAX
on overflow.
Examples
#![feature(nonzero_ops)] let two = NonZeroIsize::new(2)?; let four = NonZeroIsize::new(4)?; let max = NonZeroIsize::new(isize::MAX)?; assert_eq!(four, two.saturating_mul(two)); assert_eq!(max, four.saturating_mul(max));Run
将非零值提高到整数幂。
检查溢出并在溢出时返回 None
。
因此,结果不能归零。
Examples
#![feature(nonzero_ops)] let three = NonZeroIsize::new(3)?; let twenty_seven = NonZeroIsize::new(27)?; let half_max = NonZeroIsize::new(isize::MAX / 2)?; assert_eq!(Some(twenty_seven), three.checked_pow(3)); assert_eq!(None, half_max.checked_pow(3));Run
将非零值提高到整数幂。
Return isize::MIN
or isize::MAX
on overflow.
Examples
#![feature(nonzero_ops)] let three = NonZeroIsize::new(3)?; let twenty_seven = NonZeroIsize::new(27)?; let max = NonZeroIsize::new(isize::MAX)?; assert_eq!(twenty_seven, three.saturating_pow(3)); assert_eq!(max, max.saturating_pow(3));Run
Trait Implementations
type Output = NonZeroIsize
type Output = NonZeroIsize
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroIsize
type Output = NonZeroIsize
应用 |
运算符后的结果类型。
执行 |
操作。 Read more
type Output = NonZeroIsize
type Output = NonZeroIsize
应用 |
运算符后的结果类型。
执行 |=
操作。 Read more
执行 |=
操作。 Read more
Converts NonZeroI16
to NonZeroIsize
losslessly.
Converts NonZeroI8
to NonZeroIsize
losslessly.
Converts a NonZeroIsize
into an isize
Converts NonZeroU8
to NonZeroIsize
losslessly.
type Err = ParseIntError
type Err = ParseIntError
可以从解析中返回的相关错误。
解析字符串 s
以返回此类型的值。 Read more
此方法测试 self
和 other
值是否相等,并由 ==
使用。 Read more
此方法测试 !=
。
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: NonZeroI32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI32>>::Error>
[src]
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI32>>::Error>
[src]Attempts to convert NonZeroI32
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI64>>::Error>
[src]
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI64>>::Error>
[src]Attempts to convert NonZeroI64
to NonZeroIsize
.
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: NonZeroIsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroI32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroU32
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroUsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroI64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroU64
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroU16
.
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: NonZeroIsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroI8
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroI16
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroIsize>>::Error>
[src]
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroIsize>>::Error>
[src]Attempts to convert NonZeroIsize
to NonZeroU8
.
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: NonZeroU16
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU16>>::Error>
[src]
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU16>>::Error>
[src]Attempts to convert NonZeroU16
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU32>>::Error>
[src]
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU32>>::Error>
[src]Attempts to convert NonZeroU32
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU64>>::Error>
[src]
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU64>>::Error>
[src]Attempts to convert NonZeroU64
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroUsize>>::Error>
[src]
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroUsize>>::Error>
[src]Attempts to convert NonZeroUsize
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
pub fn try_from(
value: isize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<isize>>::Error>
[src]
pub fn try_from(
value: isize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<isize>>::Error>
[src]Attempts to convert isize
to NonZeroIsize
.
type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。