pub struct NonZero<T: ZeroablePrimitive>(/* private fields */);Expand description
Implementations§
Source§impl<T> NonZero<T>where
T: ZeroablePrimitive,
impl<T> NonZero<T>where
T: ZeroablePrimitive,
1.28.0 (const: 1.47.0) · Sourcepub const fn new(n: T) -> Option<Self>
pub const fn new(n: T) -> Option<Self>
Creates a non-zero if the given value is not zero.
1.28.0 (const: 1.28.0) · Sourcepub const unsafe fn new_unchecked(n: T) -> Self
pub const unsafe fn new_unchecked(n: T) -> Self
Creates a non-zero without checking whether the value is non-zero. This results in undefined behavior if the value is zero.
§Safety
The value must not be zero.
Sourcepub fn from_mut(n: &mut T) -> Option<&mut Self>
🔬This is a nightly-only experimental API. (nonzero_from_mut #106290)
pub fn from_mut(n: &mut T) -> Option<&mut Self>
nonzero_from_mut #106290)Converts a reference to a non-zero mutable reference if the referenced value is not zero.
Sourcepub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self
🔬This is a nightly-only experimental API. (nonzero_from_mut #106290)
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self
nonzero_from_mut #106290)Converts a mutable reference to a non-zero mutable reference without checking whether the referenced value is non-zero. This results in undefined behavior if the referenced value is zero.
§Safety
The referenced value must not be zero.
Source§impl NonZero<u8>
impl NonZero<u8>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: u8) -> Option<Self>
pub const fn checked_add(self, other: u8) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: u8) -> Self
pub const fn saturating_add(self, other: u8) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<u8>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: u8) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u8) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > u8::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
u8::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<u8>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > u8::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<u8>::MAX on overflow.
§Examples
Source§impl NonZero<u8>
impl NonZero<u8>
Source§impl NonZero<u16>
impl NonZero<u16>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: u16) -> Option<Self>
pub const fn checked_add(self, other: u16) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: u16) -> Self
pub const fn saturating_add(self, other: u16) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<u16>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: u16) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u16) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > u16::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
This is the same operation as
u16::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
u16::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<u16>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > u16::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<u16>::MAX on overflow.
§Examples
Source§impl NonZero<u16>
impl NonZero<u16>
Source§impl NonZero<u32>
impl NonZero<u32>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: u32) -> Option<Self>
pub const fn checked_add(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: u32) -> Self
pub const fn saturating_add(self, other: u32) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<u32>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u32) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > u32::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
This is the same operation as
u32::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
u32::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<u32>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > u32::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<u32>::MAX on overflow.
§Examples
Source§impl NonZero<u32>
impl NonZero<u32>
Source§impl NonZero<u64>
impl NonZero<u64>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: u64) -> Option<Self>
pub const fn checked_add(self, other: u64) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: u64) -> Self
pub const fn saturating_add(self, other: u64) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<u64>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: u64) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u64) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > u64::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
This is the same operation as
u64::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
u64::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<u64>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > u64::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<u64>::MAX on overflow.
§Examples
Source§impl NonZero<u64>
impl NonZero<u64>
Source§impl NonZero<u128>
impl NonZero<u128>
1.67.0 · Sourcepub const BITS: u32 = 128u32
pub const BITS: u32 = 128u32
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: u128) -> Option<Self>
pub const fn checked_add(self, other: u128) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: u128) -> Self
pub const fn saturating_add(self, other: u128) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<u128>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: u128) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u128) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > u128::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
Returns the smallest power of two greater than or equal to self.
Checks for overflow and returns None
if the next power of two is greater than the type’s maximum value.
As a consequence, the result cannot wrap to zero.
§Examples
let two = NonZero::new(2u128)?;
let three = NonZero::new(3u128)?;
let four = NonZero::new(4u128)?;
let max = NonZero::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() );1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
This is the same operation as
u128::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
u128::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<u128>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > u128::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<u128>::MAX on overflow.
§Examples
Source§impl NonZero<u128>
impl NonZero<u128>
Source§impl NonZero<usize>
impl NonZero<usize>
1.67.0 · Sourcepub const BITS: u32 = 64u32
pub const BITS: u32 = 64u32
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero integer type, 1.
§Examples
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this non-zero
integer type,
equal to usize::MAX.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_add(self, other: usize) -> Option<Self>
pub const fn checked_add(self, other: usize) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_add(self, other: usize) -> Self
pub const fn saturating_add(self, other: usize) -> Self
Adds an unsigned integer to a non-zero value.
Return NonZero::<usize>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_add(self, other: usize) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: usize) -> Self
nonzero_ops #84186)Adds an unsigned integer to a non-zero value,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self + rhs > usize::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_next_power_of_two(self) -> Option<Self>
pub const fn checked_next_power_of_two(self) -> Option<Self>
Returns the smallest power of two greater than or equal to self.
Checks for overflow and returns None
if the next power of two is greater than the type’s maximum value.
As a consequence, the result cannot wrap to zero.
§Examples
let two = NonZero::new(2usize)?;
let three = NonZero::new(3usize)?;
let four = NonZero::new(4usize)?;
let max = NonZero::new(usize::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() );1.67.0 (const: 1.67.0) · Sourcepub const fn ilog2(self) -> u32
pub const fn ilog2(self) -> u32
Returns the base 2 logarithm of the number, rounded down.
This is the same operation as
usize::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.67.0 (const: 1.67.0) · Sourcepub const fn ilog10(self) -> u32
pub const fn ilog10(self) -> u32
Returns the base 10 logarithm of the number, rounded down.
This is the same operation as
usize::ilog10,
except that it has no failure cases to worry about
since this value can never be zero.
§Examples
1.85.0 (const: 1.85.0) · Sourcepub const fn midpoint(self, rhs: Self) -> Self
pub const fn midpoint(self, rhs: Self) -> Self
Calculates the middle point of self and rhs.
midpoint(a, b) is (a + b) >> 1 as if it were performed in a
sufficiently-large signed integral type. This implies that the result is
always rounded towards negative infinity and that no overflow will ever occur.
§Examples
1.59.0 (const: 1.59.0) · Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
Returns true if and only if self == (1 << k) for some k.
On many architectures, this function can perform better than is_power_of_two()
on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.84.0 (const: 1.84.0) · Sourcepub const fn isqrt(self) -> Self
pub const fn isqrt(self) -> Self
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<usize>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > usize::MAX.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<usize>::MAX on overflow.
§Examples
Source§impl NonZero<usize>
impl NonZero<usize>
Source§impl NonZero<i8>
impl NonZero<i8>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
i8::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
i8::saturating_abs.
§Example
let pos = NonZero::new(1i8)?;
let neg = NonZero::new(-1i8)?;
let min = NonZero::new(i8::MIN)?;
let min_plus = NonZero::new(i8::MIN + 1)?;
let max = NonZero::new(i8::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
i8::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<u8>
pub const fn unsigned_abs(self) -> NonZero<u8>
Computes the absolute value of self without any wrapping or panicking.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<i8>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See i8::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<i8>::MAX
if self == NonZero::<i8>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5i8)?;
let neg_five = NonZero::new(-5i8)?;
let min = NonZero::new(i8::MIN)?;
let min_plus_one = NonZero::new(i8::MIN + 1)?;
let max = NonZero::new(i8::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i8::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<i8>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > i8::MAX, or self * rhs < i8::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<i8>::MIN or NonZero::<i8>::MAX on overflow.
§Examples
Source§impl NonZero<i16>
impl NonZero<i16>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
i16::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
i16::saturating_abs.
§Example
let pos = NonZero::new(1i16)?;
let neg = NonZero::new(-1i16)?;
let min = NonZero::new(i16::MIN)?;
let min_plus = NonZero::new(i16::MIN + 1)?;
let max = NonZero::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
i16::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<u16>
pub const fn unsigned_abs(self) -> NonZero<u16>
Computes the absolute value of self without any wrapping or panicking.
§Example
let u_pos = NonZero::new(1u16)?;
let i_pos = NonZero::new(1i16)?;
let i_neg = NonZero::new(-1i16)?;
let i_min = NonZero::new(i16::MIN)?;
let u_max = NonZero::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());1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<i16>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See i16::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<i16>::MAX
if self == NonZero::<i16>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5i16)?;
let neg_five = NonZero::new(-5i16)?;
let min = NonZero::new(i16::MIN)?;
let min_plus_one = NonZero::new(i16::MIN + 1)?;
let max = NonZero::new(i16::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i16::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<i16>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > i16::MAX, or self * rhs < i16::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<i16>::MIN or NonZero::<i16>::MAX on overflow.
§Examples
Source§impl NonZero<i32>
impl NonZero<i32>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
i32::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
i32::saturating_abs.
§Example
let pos = NonZero::new(1i32)?;
let neg = NonZero::new(-1i32)?;
let min = NonZero::new(i32::MIN)?;
let min_plus = NonZero::new(i32::MIN + 1)?;
let max = NonZero::new(i32::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
i32::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<u32>
pub const fn unsigned_abs(self) -> NonZero<u32>
Computes the absolute value of self without any wrapping or panicking.
§Example
let u_pos = NonZero::new(1u32)?;
let i_pos = NonZero::new(1i32)?;
let i_neg = NonZero::new(-1i32)?;
let i_min = NonZero::new(i32::MIN)?;
let u_max = NonZero::new(u32::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());1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<i32>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See i32::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<i32>::MAX
if self == NonZero::<i32>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5i32)?;
let neg_five = NonZero::new(-5i32)?;
let min = NonZero::new(i32::MIN)?;
let min_plus_one = NonZero::new(i32::MIN + 1)?;
let max = NonZero::new(i32::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i32::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<i32>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > i32::MAX, or self * rhs < i32::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<i32>::MIN or NonZero::<i32>::MAX on overflow.
§Examples
Source§impl NonZero<i64>
impl NonZero<i64>
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
i64::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
i64::saturating_abs.
§Example
let pos = NonZero::new(1i64)?;
let neg = NonZero::new(-1i64)?;
let min = NonZero::new(i64::MIN)?;
let min_plus = NonZero::new(i64::MIN + 1)?;
let max = NonZero::new(i64::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
i64::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<u64>
pub const fn unsigned_abs(self) -> NonZero<u64>
Computes the absolute value of self without any wrapping or panicking.
§Example
let u_pos = NonZero::new(1u64)?;
let i_pos = NonZero::new(1i64)?;
let i_neg = NonZero::new(-1i64)?;
let i_min = NonZero::new(i64::MIN)?;
let u_max = NonZero::new(u64::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());1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<i64>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See i64::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<i64>::MAX
if self == NonZero::<i64>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5i64)?;
let neg_five = NonZero::new(-5i64)?;
let min = NonZero::new(i64::MIN)?;
let min_plus_one = NonZero::new(i64::MIN + 1)?;
let max = NonZero::new(i64::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i64::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<i64>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > i64::MAX, or self * rhs < i64::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<i64>::MIN or NonZero::<i64>::MAX on overflow.
§Examples
Source§impl NonZero<i128>
impl NonZero<i128>
1.67.0 · Sourcepub const BITS: u32 = 128u32
pub const BITS: u32 = 128u32
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
i128::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
i128::saturating_abs.
§Example
let pos = NonZero::new(1i128)?;
let neg = NonZero::new(-1i128)?;
let min = NonZero::new(i128::MIN)?;
let min_plus = NonZero::new(i128::MIN + 1)?;
let max = NonZero::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
i128::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<u128>
pub const fn unsigned_abs(self) -> NonZero<u128>
Computes the absolute value of self without any wrapping or panicking.
§Example
let u_pos = NonZero::new(1u128)?;
let i_pos = NonZero::new(1i128)?;
let i_neg = NonZero::new(-1i128)?;
let i_min = NonZero::new(i128::MIN)?;
let u_max = NonZero::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());1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<i128>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See i128::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<i128>::MAX
if self == NonZero::<i128>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5i128)?;
let neg_five = NonZero::new(-5i128)?;
let min = NonZero::new(i128::MIN)?;
let min_plus_one = NonZero::new(i128::MIN + 1)?;
let max = NonZero::new(i128::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i128::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<i128>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > i128::MAX, or self * rhs < i128::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<i128>::MIN or NonZero::<i128>::MAX on overflow.
§Examples
Source§impl NonZero<isize>
impl NonZero<isize>
1.67.0 · Sourcepub const BITS: u32 = 64u32
pub const BITS: u32 = 64u32
1.70.0 · Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this non-zero
integer type,
equal to isize::MIN.
Note: While most integer types are defined for every whole
number between MIN and MAX, signed non-zero integers are
a special case. They have a “gap” at 0.
§Examples
1.70.0 · Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this non-zero
integer type,
equal to isize::MAX.
Note: While most integer types are defined for every whole
number between MIN and MAX, signed non-zero integers are
a special case. They have a “gap” at 0.
§Examples
1.53.0 (const: 1.53.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
On many architectures, this function can perform better than leading_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
1.53.0 (const: 1.53.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
On many architectures, this function can perform better than trailing_zeros() on the underlying integer type, as special handling of zero can be avoided.
§Examples
Basic usage:
Sourcepub const fn count_ones(self) -> NonZero<u32>
🔬This is a nightly-only experimental API. (non_zero_count_ones #120287)
pub const fn count_ones(self) -> NonZero<u32>
non_zero_count_ones #120287)Sourcepub const fn rotate_left(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the << shifting operator!
§Examples
Basic usage:
Sourcepub const fn rotate_right(self, n: u32) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> Self
nonzero_bitwise #128281)Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
Basic usage:
Sourcepub const fn swap_bytes(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> Self
nonzero_bitwise #128281)Sourcepub const fn reverse_bits(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> Self
nonzero_bitwise #128281)Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
Sourcepub const fn from_be(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn from_le(x: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: Self) -> Self
nonzero_bitwise #128281)Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_be(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> Self
nonzero_bitwise #128281)Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
Sourcepub const fn to_le(self) -> Self
🔬This is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> Self
nonzero_bitwise #128281)Converts self to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
1.64.0 (const: 1.64.0) · Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Computes the absolute value of self.
See isize::abs
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn overflowing_abs(self) -> (Self, bool)
pub const fn overflowing_abs(self) -> (Self, bool)
Computes the absolute value of self,
with overflow information, see
isize::overflowing_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_abs(self) -> Self
pub const fn saturating_abs(self) -> Self
Saturating absolute value, see
isize::saturating_abs.
§Example
let pos = NonZero::new(1isize)?;
let neg = NonZero::new(-1isize)?;
let min = NonZero::new(isize::MIN)?;
let min_plus = NonZero::new(isize::MIN + 1)?;
let max = NonZero::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());1.64.0 (const: 1.64.0) · Sourcepub const fn wrapping_abs(self) -> Self
pub const fn wrapping_abs(self) -> Self
Wrapping absolute value, see
isize::wrapping_abs.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn unsigned_abs(self) -> NonZero<usize>
pub const fn unsigned_abs(self) -> NonZero<usize>
Computes the absolute value of self without any wrapping or panicking.
§Example
let u_pos = NonZero::new(1usize)?;
let i_pos = NonZero::new(1isize)?;
let i_neg = NonZero::new(-1isize)?;
let i_min = NonZero::new(isize::MIN)?;
let u_max = NonZero::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());1.71.0 (const: 1.71.0) · Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the
number is negative.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the
number is positive.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self,
returning None if self == NonZero::<isize>::MIN.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Negates self, overflowing if this is equal to the minimum value.
See isize::overflowing_neg
for documentation on overflow behavior.
§Example
1.71.0 (const: 1.71.0) · Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Computes -self,
returning NonZero::<isize>::MAX
if self == NonZero::<isize>::MIN
instead of overflowing.
§Example
let pos_five = NonZero::new(5isize)?;
let neg_five = NonZero::new(-5isize)?;
let min = NonZero::new(isize::MIN)?;
let min_plus_one = NonZero::new(isize::MIN + 1)?;
let max = NonZero::new(isize::MAX)?;
assert_eq!(pos_five.saturating_neg(), neg_five);
assert_eq!(min.saturating_neg(), max);
assert_eq!(max.saturating_neg(), min_plus_one);1.71.0 (const: 1.71.0) · Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See isize::wrapping_neg
for documentation on overflow behavior.
§Example
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_mul(self, other: Self) -> Option<Self>
pub const fn checked_mul(self, other: Self) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_mul(self, other: Self) -> Self
pub const fn saturating_mul(self, other: Self) -> Self
Multiplies two non-zero integers together.
Return NonZero::<isize>::MAX on overflow.
§Examples
Sourcepub const unsafe fn unchecked_mul(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: Self) -> Self
nonzero_ops #84186)Multiplies two non-zero integers together,
assuming overflow cannot occur.
Overflow is unchecked, and it is undefined behavior to overflow
even if the result would wrap to a non-zero value.
The behavior is undefined as soon as
self * rhs > isize::MAX, or self * rhs < isize::MIN.
§Examples
1.64.0 (const: 1.64.0) · Sourcepub const fn checked_pow(self, other: u32) -> Option<Self>
pub const fn checked_pow(self, other: u32) -> Option<Self>
1.64.0 (const: 1.64.0) · Sourcepub const fn saturating_pow(self, other: u32) -> Self
pub const fn saturating_pow(self, other: u32) -> Self
Raise non-zero value to an integer power.
Return NonZero::<isize>::MIN or NonZero::<isize>::MAX on overflow.
§Examples
Trait Implementations§
1.45.0 · Source§impl<T> BitOrAssign<T> for NonZero<T>where
T: ZeroablePrimitive,
Self: BitOr<T, Output = Self>,
impl<T> BitOrAssign<T> for NonZero<T>where
T: ZeroablePrimitive,
Self: BitOr<T, Output = Self>,
Source§fn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
|= operation. Read more1.45.0 · Source§impl<T> BitOrAssign for NonZero<T>where
T: ZeroablePrimitive,
Self: BitOr<Output = Self>,
impl<T> BitOrAssign for NonZero<T>where
T: ZeroablePrimitive,
Self: BitOr<Output = Self>,
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read more1.28.0 · Source§impl<T> Clone for NonZero<T>where
T: ZeroablePrimitive,
impl<T> Clone for NonZero<T>where
T: ZeroablePrimitive,
1.79.0 · Source§impl DivAssign<NonZero<u128>> for u128
impl DivAssign<NonZero<u128>> for u128
Source§fn div_assign(&mut self, other: NonZero<u128>)
fn div_assign(&mut self, other: NonZero<u128>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 · Source§impl DivAssign<NonZero<u16>> for u16
impl DivAssign<NonZero<u16>> for u16
Source§fn div_assign(&mut self, other: NonZero<u16>)
fn div_assign(&mut self, other: NonZero<u16>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 · Source§impl DivAssign<NonZero<u32>> for u32
impl DivAssign<NonZero<u32>> for u32
Source§fn div_assign(&mut self, other: NonZero<u32>)
fn div_assign(&mut self, other: NonZero<u32>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 · Source§impl DivAssign<NonZero<u64>> for u64
impl DivAssign<NonZero<u64>> for u64
Source§fn div_assign(&mut self, other: NonZero<u64>)
fn div_assign(&mut self, other: NonZero<u64>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 · Source§impl DivAssign<NonZero<u8>> for u8
impl DivAssign<NonZero<u8>> for u8
Source§fn div_assign(&mut self, other: NonZero<u8>)
fn div_assign(&mut self, other: NonZero<u8>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 · Source§impl DivAssign<NonZero<usize>> for usize
impl DivAssign<NonZero<usize>> for usize
Source§fn div_assign(&mut self, other: NonZero<usize>)
fn div_assign(&mut self, other: NonZero<usize>)
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.28.0 · Source§impl<T> Ord for NonZero<T>where
T: ZeroablePrimitive + Ord,
impl<T> Ord for NonZero<T>where
T: ZeroablePrimitive + Ord,
1.28.0 · Source§impl<T> PartialOrd for NonZero<T>where
T: ZeroablePrimitive + PartialOrd,
impl<T> PartialOrd for NonZero<T>where
T: ZeroablePrimitive + PartialOrd,
1.79.0 · Source§impl RemAssign<NonZero<u128>> for u128
impl RemAssign<NonZero<u128>> for u128
Source§fn rem_assign(&mut self, other: NonZero<u128>)
fn rem_assign(&mut self, other: NonZero<u128>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.
1.79.0 · Source§impl RemAssign<NonZero<u16>> for u16
impl RemAssign<NonZero<u16>> for u16
Source§fn rem_assign(&mut self, other: NonZero<u16>)
fn rem_assign(&mut self, other: NonZero<u16>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.
1.79.0 · Source§impl RemAssign<NonZero<u32>> for u32
impl RemAssign<NonZero<u32>> for u32
Source§fn rem_assign(&mut self, other: NonZero<u32>)
fn rem_assign(&mut self, other: NonZero<u32>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.
1.79.0 · Source§impl RemAssign<NonZero<u64>> for u64
impl RemAssign<NonZero<u64>> for u64
Source§fn rem_assign(&mut self, other: NonZero<u64>)
fn rem_assign(&mut self, other: NonZero<u64>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.
1.79.0 · Source§impl RemAssign<NonZero<u8>> for u8
impl RemAssign<NonZero<u8>> for u8
Source§fn rem_assign(&mut self, other: NonZero<u8>)
fn rem_assign(&mut self, other: NonZero<u8>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.
1.79.0 · Source§impl RemAssign<NonZero<usize>> for usize
impl RemAssign<NonZero<usize>> for usize
Source§fn rem_assign(&mut self, other: NonZero<usize>)
fn rem_assign(&mut self, other: NonZero<usize>)
This operation satisfies n % d == n - (n / d) * d, and cannot panic.