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