pub struct NonZero<T>(/* private fields */)
where
T: ZeroablePrimitive;Expand description
A value that is known not to equal zero.
This enables some memory layout optimization.
For example, Option<NonZero<u32>> is the same size as u32:
ยงLayout
NonZero<T> is guaranteed to have the same layout and bit validity as T
with the exception that the all-zero bit pattern is invalid.
Option<NonZero<T>> is guaranteed to be compatible with T, including in
FFI.
Thanks to the null pointer optimization, NonZero<T> and
Option<NonZero<T>> are guaranteed to have the same size and alignment:
use std::num::NonZero;
assert_eq!(size_of::<NonZero<u32>>(), size_of::<Option<NonZero<u32>>>());
assert_eq!(align_of::<NonZero<u32>>(), align_of::<Option<NonZero<u32>>>());ยงNote on generic usage
NonZero<T> can only be used with some standard library primitive types
(such as u8, i32, and etc.). The type parameter T must implement the
internal trait ZeroablePrimitive, which is currently permanently unstable
and cannot be implemented by users. Therefore, you cannot use NonZero<T>
with your own types, nor can you implement traits for all NonZero<T>,
only for concrete types.
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<NonZero<T>>
pub const fn new(n: T) -> Option<NonZero<T>>
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) -> NonZero<T>
pub const unsafe fn new_unchecked(n: T) -> NonZero<T>
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 NonZero<T>>
๐ฌThis is a nightly-only experimental API. (nonzero_from_mut #106290)
pub fn from_mut(n: &mut T) -> Option<&mut NonZero<T>>
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 NonZero<T>
๐ฌThis is a nightly-only experimental API. (nonzero_from_mut #106290)
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut NonZero<T>
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: NonZero<u8>
pub const MIN: NonZero<u8>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<u8>
pub const fn isolate_highest_one(self) -> NonZero<u8>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<u8>
pub const fn isolate_lowest_one(self) -> NonZero<u8>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<u8>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<u8>
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
Sourcepub const fn swap_bytes(self) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<u8>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<u8>
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
Sourcepub const fn from_be(x: NonZero<u8>) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<u8>) -> NonZero<u8>
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
Sourcepub const fn from_le(x: NonZero<u8>) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<u8>) -> NonZero<u8>
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
Sourcepub const fn to_be(self) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<u8>
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
Sourcepub const fn to_le(self) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<u8>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: u8) -> Option<NonZero<u8>>
pub const fn checked_add(self, other: u8) -> Option<NonZero<u8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: u8) -> NonZero<u8>
pub const fn saturating_add(self, other: u8) -> NonZero<u8>
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) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u8) -> NonZero<u8>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<u8>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<u8>>
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
u8::ilog2,
except that it has no failure cases to worry about
since this value can never be zero.
Note that this is equivalent to highest_one.
ยง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
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: NonZero<u8>) -> NonZero<u8>
pub const fn midpoint(self, rhs: NonZero<u8>) -> NonZero<u8>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<u8>
pub const fn isqrt(self) -> NonZero<u8>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<i8>
pub const fn cast_signed(self) -> NonZero<i8>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<u8>) -> Option<NonZero<u8>>
pub const fn checked_mul(self, other: NonZero<u8>) -> Option<NonZero<u8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<u8>) -> NonZero<u8>
pub const fn saturating_mul(self, other: NonZero<u8>) -> NonZero<u8>
Multiplies two non-zero integers together.
Return NonZero::<u8>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<u8>) -> NonZero<u8>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<u8>) -> NonZero<u8>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<u8>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<u8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<u8>
pub const fn saturating_pow(self, other: u32) -> NonZero<u8>
Raise non-zero value to an integer power.
Return NonZero::<u8>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<u8>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<u8>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<u8>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<u8>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<u8>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<u8>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<u8>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<u8>
impl NonZero<u8>
Sourceยงimpl NonZero<u16>
impl NonZero<u16>
1.70.0 ยท Sourcepub const MIN: NonZero<u16>
pub const MIN: NonZero<u16>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<u16>
pub const fn isolate_highest_one(self) -> NonZero<u16>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<u16>
pub const fn isolate_lowest_one(self) -> NonZero<u16>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<u16>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<u16>
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
Sourcepub const fn swap_bytes(self) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<u16>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<u16>
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
Sourcepub const fn from_be(x: NonZero<u16>) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<u16>) -> NonZero<u16>
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
Sourcepub const fn from_le(x: NonZero<u16>) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<u16>) -> NonZero<u16>
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
Sourcepub const fn to_be(self) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<u16>
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
Sourcepub const fn to_le(self) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<u16>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: u16) -> Option<NonZero<u16>>
pub const fn checked_add(self, other: u16) -> Option<NonZero<u16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: u16) -> NonZero<u16>
pub const fn saturating_add(self, other: u16) -> NonZero<u16>
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) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u16) -> NonZero<u16>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<u16>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<u16>>
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.
Note that this is equivalent to highest_one.
ยง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: NonZero<u16>) -> NonZero<u16>
pub const fn midpoint(self, rhs: NonZero<u16>) -> NonZero<u16>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<u16>
pub const fn isqrt(self) -> NonZero<u16>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<i16>
pub const fn cast_signed(self) -> NonZero<i16>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<u16>) -> Option<NonZero<u16>>
pub const fn checked_mul(self, other: NonZero<u16>) -> Option<NonZero<u16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<u16>) -> NonZero<u16>
pub const fn saturating_mul(self, other: NonZero<u16>) -> NonZero<u16>
Multiplies two non-zero integers together.
Return NonZero::<u16>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<u16>) -> NonZero<u16>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<u16>) -> NonZero<u16>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<u16>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<u16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<u16>
pub const fn saturating_pow(self, other: u32) -> NonZero<u16>
Raise non-zero value to an integer power.
Return NonZero::<u16>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<u16>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<u16>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<u16>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<u16>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<u16>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<u16>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<u16>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<u16>
impl NonZero<u16>
Sourceยงimpl NonZero<u32>
impl NonZero<u32>
1.70.0 ยท Sourcepub const MIN: NonZero<u32>
pub const MIN: NonZero<u32>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<u32>
pub const fn isolate_highest_one(self) -> NonZero<u32>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<u32>
pub const fn isolate_lowest_one(self) -> NonZero<u32>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<u32>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<u32>
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
Sourcepub const fn swap_bytes(self) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<u32>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<u32>
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
Sourcepub const fn from_be(x: NonZero<u32>) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<u32>) -> NonZero<u32>
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
Sourcepub const fn from_le(x: NonZero<u32>) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<u32>) -> NonZero<u32>
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
Sourcepub const fn to_be(self) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<u32>
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
Sourcepub const fn to_le(self) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<u32>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: u32) -> Option<NonZero<u32>>
pub const fn checked_add(self, other: u32) -> Option<NonZero<u32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: u32) -> NonZero<u32>
pub const fn saturating_add(self, other: u32) -> NonZero<u32>
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) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u32) -> NonZero<u32>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<u32>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<u32>>
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.
Note that this is equivalent to highest_one.
ยง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: NonZero<u32>) -> NonZero<u32>
pub const fn midpoint(self, rhs: NonZero<u32>) -> NonZero<u32>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<u32>
pub const fn isqrt(self) -> NonZero<u32>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<i32>
pub const fn cast_signed(self) -> NonZero<i32>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<u32>) -> Option<NonZero<u32>>
pub const fn checked_mul(self, other: NonZero<u32>) -> Option<NonZero<u32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<u32>) -> NonZero<u32>
pub const fn saturating_mul(self, other: NonZero<u32>) -> NonZero<u32>
Multiplies two non-zero integers together.
Return NonZero::<u32>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<u32>) -> NonZero<u32>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<u32>) -> NonZero<u32>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<u32>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<u32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<u32>
pub const fn saturating_pow(self, other: u32) -> NonZero<u32>
Raise non-zero value to an integer power.
Return NonZero::<u32>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<u32>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<u32>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<u32>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<u32>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<u32>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<u32>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<u32>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<u32>
impl NonZero<u32>
Sourceยงimpl NonZero<u64>
impl NonZero<u64>
1.70.0 ยท Sourcepub const MIN: NonZero<u64>
pub const MIN: NonZero<u64>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<u64>
pub const fn isolate_highest_one(self) -> NonZero<u64>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<u64>
pub const fn isolate_lowest_one(self) -> NonZero<u64>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<u64>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<u64>
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
Sourcepub const fn swap_bytes(self) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<u64>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<u64>
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
Sourcepub const fn from_be(x: NonZero<u64>) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<u64>) -> NonZero<u64>
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
Sourcepub const fn from_le(x: NonZero<u64>) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<u64>) -> NonZero<u64>
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
Sourcepub const fn to_be(self) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<u64>
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
Sourcepub const fn to_le(self) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<u64>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: u64) -> Option<NonZero<u64>>
pub const fn checked_add(self, other: u64) -> Option<NonZero<u64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: u64) -> NonZero<u64>
pub const fn saturating_add(self, other: u64) -> NonZero<u64>
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) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u64) -> NonZero<u64>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<u64>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<u64>>
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.
Note that this is equivalent to highest_one.
ยง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: NonZero<u64>) -> NonZero<u64>
pub const fn midpoint(self, rhs: NonZero<u64>) -> NonZero<u64>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<u64>
pub const fn isqrt(self) -> NonZero<u64>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<i64>
pub const fn cast_signed(self) -> NonZero<i64>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<u64>) -> Option<NonZero<u64>>
pub const fn checked_mul(self, other: NonZero<u64>) -> Option<NonZero<u64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<u64>) -> NonZero<u64>
pub const fn saturating_mul(self, other: NonZero<u64>) -> NonZero<u64>
Multiplies two non-zero integers together.
Return NonZero::<u64>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<u64>) -> NonZero<u64>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<u64>) -> NonZero<u64>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<u64>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<u64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<u64>
pub const fn saturating_pow(self, other: u32) -> NonZero<u64>
Raise non-zero value to an integer power.
Return NonZero::<u64>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<u64>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<u64>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<u64>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<u64>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<u64>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<u64>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<u64>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<u64>
impl NonZero<u64>
Sourceยงimpl NonZero<u128>
impl NonZero<u128>
1.67.0 ยท Sourcepub const BITS: u32 = u128::BITS
pub const BITS: u32 = u128::BITS
1.70.0 ยท Sourcepub const MIN: NonZero<u128>
pub const MIN: NonZero<u128>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<u128>
pub const fn isolate_highest_one(self) -> NonZero<u128>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<u128>
pub const fn isolate_lowest_one(self) -> NonZero<u128>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<u128>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<u128>
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
Sourcepub const fn swap_bytes(self) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<u128>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<u128>
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
Sourcepub const fn from_be(x: NonZero<u128>) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<u128>) -> NonZero<u128>
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
Sourcepub const fn from_le(x: NonZero<u128>) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<u128>) -> NonZero<u128>
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
Sourcepub const fn to_be(self) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<u128>
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
Sourcepub const fn to_le(self) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<u128>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: u128) -> Option<NonZero<u128>>
pub const fn checked_add(self, other: u128) -> Option<NonZero<u128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: u128) -> NonZero<u128>
pub const fn saturating_add(self, other: u128) -> NonZero<u128>
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) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: u128) -> NonZero<u128>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<u128>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<u128>>
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.
Note that this is equivalent to highest_one.
ยง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: NonZero<u128>) -> NonZero<u128>
pub const fn midpoint(self, rhs: NonZero<u128>) -> NonZero<u128>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<u128>
pub const fn isqrt(self) -> NonZero<u128>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<i128>
pub const fn cast_signed(self) -> NonZero<i128>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<u128>) -> Option<NonZero<u128>>
pub const fn checked_mul(self, other: NonZero<u128>) -> Option<NonZero<u128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<u128>) -> NonZero<u128>
pub const fn saturating_mul(self, other: NonZero<u128>) -> NonZero<u128>
Multiplies two non-zero integers together.
Return NonZero::<u128>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<u128>) -> NonZero<u128>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<u128>) -> NonZero<u128>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<u128>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<u128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<u128>
pub const fn saturating_pow(self, other: u32) -> NonZero<u128>
Raise non-zero value to an integer power.
Return NonZero::<u128>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<u128>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<u128>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<u128>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<u128>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<u128>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<u128>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<u128>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<u128>
impl NonZero<u128>
Sourceยงimpl NonZero<usize>
impl NonZero<usize>
1.67.0 ยท Sourcepub const BITS: u32 = usize::BITS
pub const BITS: u32 = usize::BITS
1.70.0 ยท Sourcepub const MIN: NonZero<usize>
pub const MIN: NonZero<usize>
The smallest value that can be represented by this non-zero integer type, 1.
ยงExamples
1.70.0 ยท Sourcepub const MAX: NonZero<usize>
pub const MAX: NonZero<usize>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<usize>
pub const fn isolate_highest_one(self) -> NonZero<usize>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<usize>
pub const fn isolate_lowest_one(self) -> NonZero<usize>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<usize>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<usize>
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
Sourcepub const fn swap_bytes(self) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<usize>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<usize>
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
Sourcepub const fn from_be(x: NonZero<usize>) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<usize>) -> NonZero<usize>
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
Sourcepub const fn from_le(x: NonZero<usize>) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<usize>) -> NonZero<usize>
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
Sourcepub const fn to_be(self) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<usize>
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
Sourcepub const fn to_le(self) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<usize>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_add(self, other: usize) -> Option<NonZero<usize>>
pub const fn checked_add(self, other: usize) -> Option<NonZero<usize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_add(self, other: usize) -> NonZero<usize>
pub const fn saturating_add(self, other: usize) -> NonZero<usize>
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) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_add(self, other: usize) -> NonZero<usize>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_next_power_of_two(self) -> Option<NonZero<usize>>
pub const fn checked_next_power_of_two(self) -> Option<NonZero<usize>>
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.
Note that this is equivalent to highest_one.
ยง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: NonZero<usize>) -> NonZero<usize>
pub const fn midpoint(self, rhs: NonZero<usize>) -> NonZero<usize>
Calculates the midpoint (average) between 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
1.84.0 (const: 1.84.0) ยท Sourcepub const fn isqrt(self) -> NonZero<usize>
pub const fn isqrt(self) -> NonZero<usize>
Returns the square root of the number, rounded down.
ยงExamples
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_signed(self) -> NonZero<isize>
pub const fn cast_signed(self) -> NonZero<isize>
Returns the bit pattern of self reinterpreted as a signed integer of the same size.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn bit_width(self) -> NonZero<u32>
pub const fn bit_width(self) -> NonZero<u32>
Returns the minimum number of bits required to represent self.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<usize>) -> Option<NonZero<usize>>
pub const fn checked_mul(self, other: NonZero<usize>) -> Option<NonZero<usize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<usize>) -> NonZero<usize>
pub const fn saturating_mul(self, other: NonZero<usize>) -> NonZero<usize>
Multiplies two non-zero integers together.
Return NonZero::<usize>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<usize>) -> NonZero<usize>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<usize>) -> NonZero<usize>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<usize>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<usize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<usize>
pub const fn saturating_pow(self, other: u32) -> NonZero<usize>
Raise non-zero value to an integer power.
Return NonZero::<usize>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<usize>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<usize>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<usize>::from_ascii(b"+10"), Ok(NonZero::new(10)?));Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<usize>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<usize>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<usize>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<usize>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<usize>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<usize>
impl NonZero<usize>
Sourceยงimpl NonZero<i8>
impl NonZero<i8>
1.70.0 ยท Sourcepub const MIN: NonZero<i8>
pub const MIN: NonZero<i8>
1.70.0 ยท Sourcepub const MAX: NonZero<i8>
pub const MAX: NonZero<i8>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<i8>
pub const fn isolate_highest_one(self) -> NonZero<i8>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<i8>
pub const fn isolate_lowest_one(self) -> NonZero<i8>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<i8>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<i8>
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
Sourcepub const fn swap_bytes(self) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<i8>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<i8>
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
Sourcepub const fn from_be(x: NonZero<i8>) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<i8>) -> NonZero<i8>
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
Sourcepub const fn from_le(x: NonZero<i8>) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<i8>) -> NonZero<i8>
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
Sourcepub const fn to_be(self) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<i8>
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
Sourcepub const fn to_le(self) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<i8>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_abs(self) -> Option<NonZero<i8>>
pub const fn checked_abs(self) -> Option<NonZero<i8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<i8>, bool)
pub const fn overflowing_abs(self) -> (NonZero<i8>, 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) -> NonZero<i8>
pub const fn saturating_abs(self) -> NonZero<i8>
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) -> NonZero<i8>
pub const fn wrapping_abs(self) -> NonZero<i8>
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<NonZero<i8>>
pub const fn checked_neg(self) -> Option<NonZero<i8>>
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) -> (NonZero<i8>, bool)
pub const fn overflowing_neg(self) -> (NonZero<i8>, 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) -> NonZero<i8>
pub const fn saturating_neg(self) -> NonZero<i8>
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) -> NonZero<i8>
pub const fn wrapping_neg(self) -> NonZero<i8>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i8::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<u8>
pub const fn cast_unsigned(self) -> NonZero<u8>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<i8>) -> Option<NonZero<i8>>
pub const fn checked_mul(self, other: NonZero<i8>) -> Option<NonZero<i8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<i8>) -> NonZero<i8>
pub const fn saturating_mul(self, other: NonZero<i8>) -> NonZero<i8>
Multiplies two non-zero integers together.
Return NonZero::<i8>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<i8>) -> NonZero<i8>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<i8>) -> NonZero<i8>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<i8>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<i8>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<i8>
pub const fn saturating_pow(self, other: u32) -> NonZero<i8>
Raise non-zero value to an integer power.
Return NonZero::<i8>::MIN or NonZero::<i8>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<i8>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<i8>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<i8>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<i8>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<i8>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<i8>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<i8>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<i16>
impl NonZero<i16>
1.70.0 ยท Sourcepub const MIN: NonZero<i16>
pub const MIN: NonZero<i16>
1.70.0 ยท Sourcepub const MAX: NonZero<i16>
pub const MAX: NonZero<i16>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<i16>
pub const fn isolate_highest_one(self) -> NonZero<i16>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<i16>
pub const fn isolate_lowest_one(self) -> NonZero<i16>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<i16>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<i16>
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
Sourcepub const fn swap_bytes(self) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<i16>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<i16>
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
Sourcepub const fn from_be(x: NonZero<i16>) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<i16>) -> NonZero<i16>
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
Sourcepub const fn from_le(x: NonZero<i16>) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<i16>) -> NonZero<i16>
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
Sourcepub const fn to_be(self) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<i16>
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
Sourcepub const fn to_le(self) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<i16>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_abs(self) -> Option<NonZero<i16>>
pub const fn checked_abs(self) -> Option<NonZero<i16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<i16>, bool)
pub const fn overflowing_abs(self) -> (NonZero<i16>, 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) -> NonZero<i16>
pub const fn saturating_abs(self) -> NonZero<i16>
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) -> NonZero<i16>
pub const fn wrapping_abs(self) -> NonZero<i16>
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<NonZero<i16>>
pub const fn checked_neg(self) -> Option<NonZero<i16>>
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) -> (NonZero<i16>, bool)
pub const fn overflowing_neg(self) -> (NonZero<i16>, 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) -> NonZero<i16>
pub const fn saturating_neg(self) -> NonZero<i16>
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) -> NonZero<i16>
pub const fn wrapping_neg(self) -> NonZero<i16>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i16::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<u16>
pub const fn cast_unsigned(self) -> NonZero<u16>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<i16>) -> Option<NonZero<i16>>
pub const fn checked_mul(self, other: NonZero<i16>) -> Option<NonZero<i16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<i16>) -> NonZero<i16>
pub const fn saturating_mul(self, other: NonZero<i16>) -> NonZero<i16>
Multiplies two non-zero integers together.
Return NonZero::<i16>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<i16>) -> NonZero<i16>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<i16>) -> NonZero<i16>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<i16>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<i16>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<i16>
pub const fn saturating_pow(self, other: u32) -> NonZero<i16>
Raise non-zero value to an integer power.
Return NonZero::<i16>::MIN or NonZero::<i16>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<i16>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<i16>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<i16>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<i16>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<i16>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<i16>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<i16>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<i32>
impl NonZero<i32>
1.70.0 ยท Sourcepub const MIN: NonZero<i32>
pub const MIN: NonZero<i32>
1.70.0 ยท Sourcepub const MAX: NonZero<i32>
pub const MAX: NonZero<i32>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<i32>
pub const fn isolate_highest_one(self) -> NonZero<i32>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<i32>
pub const fn isolate_lowest_one(self) -> NonZero<i32>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<i32>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<i32>
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
Sourcepub const fn swap_bytes(self) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<i32>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<i32>
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
Sourcepub const fn from_be(x: NonZero<i32>) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<i32>) -> NonZero<i32>
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
Sourcepub const fn from_le(x: NonZero<i32>) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<i32>) -> NonZero<i32>
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
Sourcepub const fn to_be(self) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<i32>
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
Sourcepub const fn to_le(self) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<i32>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_abs(self) -> Option<NonZero<i32>>
pub const fn checked_abs(self) -> Option<NonZero<i32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<i32>, bool)
pub const fn overflowing_abs(self) -> (NonZero<i32>, 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) -> NonZero<i32>
pub const fn saturating_abs(self) -> NonZero<i32>
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) -> NonZero<i32>
pub const fn wrapping_abs(self) -> NonZero<i32>
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<NonZero<i32>>
pub const fn checked_neg(self) -> Option<NonZero<i32>>
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) -> (NonZero<i32>, bool)
pub const fn overflowing_neg(self) -> (NonZero<i32>, 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) -> NonZero<i32>
pub const fn saturating_neg(self) -> NonZero<i32>
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) -> NonZero<i32>
pub const fn wrapping_neg(self) -> NonZero<i32>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i32::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<u32>
pub const fn cast_unsigned(self) -> NonZero<u32>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<i32>) -> Option<NonZero<i32>>
pub const fn checked_mul(self, other: NonZero<i32>) -> Option<NonZero<i32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<i32>) -> NonZero<i32>
pub const fn saturating_mul(self, other: NonZero<i32>) -> NonZero<i32>
Multiplies two non-zero integers together.
Return NonZero::<i32>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<i32>) -> NonZero<i32>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<i32>) -> NonZero<i32>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<i32>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<i32>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<i32>
pub const fn saturating_pow(self, other: u32) -> NonZero<i32>
Raise non-zero value to an integer power.
Return NonZero::<i32>::MIN or NonZero::<i32>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<i32>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<i32>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<i32>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<i32>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<i32>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<i32>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<i32>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<i64>
impl NonZero<i64>
1.70.0 ยท Sourcepub const MIN: NonZero<i64>
pub const MIN: NonZero<i64>
1.70.0 ยท Sourcepub const MAX: NonZero<i64>
pub const MAX: NonZero<i64>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<i64>
pub const fn isolate_highest_one(self) -> NonZero<i64>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<i64>
pub const fn isolate_lowest_one(self) -> NonZero<i64>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<i64>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<i64>
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
Sourcepub const fn swap_bytes(self) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<i64>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<i64>
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
Sourcepub const fn from_be(x: NonZero<i64>) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<i64>) -> NonZero<i64>
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
Sourcepub const fn from_le(x: NonZero<i64>) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<i64>) -> NonZero<i64>
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
Sourcepub const fn to_be(self) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<i64>
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
Sourcepub const fn to_le(self) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<i64>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_abs(self) -> Option<NonZero<i64>>
pub const fn checked_abs(self) -> Option<NonZero<i64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<i64>, bool)
pub const fn overflowing_abs(self) -> (NonZero<i64>, 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) -> NonZero<i64>
pub const fn saturating_abs(self) -> NonZero<i64>
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) -> NonZero<i64>
pub const fn wrapping_abs(self) -> NonZero<i64>
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<NonZero<i64>>
pub const fn checked_neg(self) -> Option<NonZero<i64>>
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) -> (NonZero<i64>, bool)
pub const fn overflowing_neg(self) -> (NonZero<i64>, 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) -> NonZero<i64>
pub const fn saturating_neg(self) -> NonZero<i64>
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) -> NonZero<i64>
pub const fn wrapping_neg(self) -> NonZero<i64>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i64::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<u64>
pub const fn cast_unsigned(self) -> NonZero<u64>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<i64>) -> Option<NonZero<i64>>
pub const fn checked_mul(self, other: NonZero<i64>) -> Option<NonZero<i64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<i64>) -> NonZero<i64>
pub const fn saturating_mul(self, other: NonZero<i64>) -> NonZero<i64>
Multiplies two non-zero integers together.
Return NonZero::<i64>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<i64>) -> NonZero<i64>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<i64>) -> NonZero<i64>
nonzero_ops #84186)1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_pow(self, other: u32) -> Option<NonZero<i64>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<i64>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<i64>
pub const fn saturating_pow(self, other: u32) -> NonZero<i64>
Raise non-zero value to an integer power.
Return NonZero::<i64>::MIN or NonZero::<i64>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<i64>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<i64>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<i64>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<i64>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<i64>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<i64>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<i64>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<i128>
impl NonZero<i128>
1.67.0 ยท Sourcepub const BITS: u32 = i128::BITS
pub const BITS: u32 = i128::BITS
1.70.0 ยท Sourcepub const MIN: NonZero<i128>
pub const MIN: NonZero<i128>
1.70.0 ยท Sourcepub const MAX: NonZero<i128>
pub const MAX: NonZero<i128>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<i128>
pub const fn isolate_highest_one(self) -> NonZero<i128>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<i128>
pub const fn isolate_lowest_one(self) -> NonZero<i128>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<i128>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<i128>
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
Sourcepub const fn swap_bytes(self) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<i128>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<i128>
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
Sourcepub const fn from_be(x: NonZero<i128>) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<i128>) -> NonZero<i128>
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
Sourcepub const fn from_le(x: NonZero<i128>) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<i128>) -> NonZero<i128>
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
Sourcepub const fn to_be(self) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<i128>
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
Sourcepub const fn to_le(self) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<i128>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_abs(self) -> Option<NonZero<i128>>
pub const fn checked_abs(self) -> Option<NonZero<i128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<i128>, bool)
pub const fn overflowing_abs(self) -> (NonZero<i128>, 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) -> NonZero<i128>
pub const fn saturating_abs(self) -> NonZero<i128>
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) -> NonZero<i128>
pub const fn wrapping_abs(self) -> NonZero<i128>
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<NonZero<i128>>
pub const fn checked_neg(self) -> Option<NonZero<i128>>
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) -> (NonZero<i128>, bool)
pub const fn overflowing_neg(self) -> (NonZero<i128>, 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) -> NonZero<i128>
pub const fn saturating_neg(self) -> NonZero<i128>
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) -> NonZero<i128>
pub const fn wrapping_neg(self) -> NonZero<i128>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See i128::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<u128>
pub const fn cast_unsigned(self) -> NonZero<u128>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<i128>) -> Option<NonZero<i128>>
pub const fn checked_mul(self, other: NonZero<i128>) -> Option<NonZero<i128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<i128>) -> NonZero<i128>
pub const fn saturating_mul(self, other: NonZero<i128>) -> NonZero<i128>
Multiplies two non-zero integers together.
Return NonZero::<i128>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<i128>) -> NonZero<i128>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<i128>) -> NonZero<i128>
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.
ยงSafety
This results in undefined behavior when
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<NonZero<i128>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<i128>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<i128>
pub const fn saturating_pow(self, other: u32) -> NonZero<i128>
Raise non-zero value to an integer power.
Return NonZero::<i128>::MIN or NonZero::<i128>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<i128>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<i128>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<i128>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<i128>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<i128>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<i128>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<i128>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Sourceยงimpl NonZero<isize>
impl NonZero<isize>
1.67.0 ยท Sourcepub const BITS: u32 = isize::BITS
pub const BITS: u32 = isize::BITS
1.70.0 ยท Sourcepub const MIN: NonZero<isize>
pub const MIN: NonZero<isize>
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: NonZero<isize>
pub const MAX: NonZero<isize>
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
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
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_highest_one(self) -> NonZero<isize>
pub const fn isolate_highest_one(self) -> NonZero<isize>
Returns self with only the most significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn isolate_lowest_one(self) -> NonZero<isize>
pub const fn isolate_lowest_one(self) -> NonZero<isize>
Returns self with only the least significant bit set.
ยงExample
1.97.0 (const: 1.97.0) ยท Sourcepub const fn highest_one(self) -> u32
pub const fn highest_one(self) -> u32
Returns the index of the highest bit set to one in self.
ยงExamples
1.97.0 (const: 1.97.0) ยท Sourcepub const fn lowest_one(self) -> u32
pub const fn lowest_one(self) -> u32
Returns the index of the lowest bit set to one in self.
ยงExamples
1.86.0 (const: 1.86.0) ยท Sourcepub const fn count_ones(self) -> NonZero<u32>
pub const fn count_ones(self) -> NonZero<u32>
Returns the number of ones in the binary representation of self.
ยงExamples
Sourcepub const fn rotate_left(self, n: u32) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_left(self, n: u32) -> NonZero<isize>
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
Sourcepub const fn rotate_right(self, n: u32) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn rotate_right(self, n: u32) -> NonZero<isize>
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
Sourcepub const fn swap_bytes(self) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn swap_bytes(self) -> NonZero<isize>
nonzero_bitwise #128281)Reverses the byte order of the integer.
ยงExamples
Sourcepub const fn reverse_bits(self) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn reverse_bits(self) -> NonZero<isize>
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
Sourcepub const fn from_be(x: NonZero<isize>) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_be(x: NonZero<isize>) -> NonZero<isize>
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
Sourcepub const fn from_le(x: NonZero<isize>) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn from_le(x: NonZero<isize>) -> NonZero<isize>
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
Sourcepub const fn to_be(self) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_be(self) -> NonZero<isize>
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
Sourcepub const fn to_le(self) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_bitwise #128281)
pub const fn to_le(self) -> NonZero<isize>
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
1.64.0 (const: 1.64.0) ยท Sourcepub const fn abs(self) -> NonZero<isize>
pub const fn abs(self) -> NonZero<isize>
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<NonZero<isize>>
pub const fn checked_abs(self) -> Option<NonZero<isize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn overflowing_abs(self) -> (NonZero<isize>, bool)
pub const fn overflowing_abs(self) -> (NonZero<isize>, 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) -> NonZero<isize>
pub const fn saturating_abs(self) -> NonZero<isize>
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) -> NonZero<isize>
pub const fn wrapping_abs(self) -> NonZero<isize>
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<NonZero<isize>>
pub const fn checked_neg(self) -> Option<NonZero<isize>>
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) -> (NonZero<isize>, bool)
pub const fn overflowing_neg(self) -> (NonZero<isize>, 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) -> NonZero<isize>
pub const fn saturating_neg(self) -> NonZero<isize>
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) -> NonZero<isize>
pub const fn wrapping_neg(self) -> NonZero<isize>
Wrapping (modular) negation. Computes -self, wrapping around at the boundary
of the type.
See isize::wrapping_neg
for documentation on overflow behavior.
ยงExample
1.87.0 (const: 1.87.0) ยท Sourcepub const fn cast_unsigned(self) -> NonZero<usize>
pub const fn cast_unsigned(self) -> NonZero<usize>
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
ยงExamples
1.64.0 (const: 1.64.0) ยท Sourcepub const fn checked_mul(self, other: NonZero<isize>) -> Option<NonZero<isize>>
pub const fn checked_mul(self, other: NonZero<isize>) -> Option<NonZero<isize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_mul(self, other: NonZero<isize>) -> NonZero<isize>
pub const fn saturating_mul(self, other: NonZero<isize>) -> NonZero<isize>
Multiplies two non-zero integers together.
Return NonZero::<isize>::MAX on overflow.
ยงExamples
Sourcepub const unsafe fn unchecked_mul(self, other: NonZero<isize>) -> NonZero<isize>
๐ฌThis is a nightly-only experimental API. (nonzero_ops #84186)
pub const unsafe fn unchecked_mul(self, other: NonZero<isize>) -> NonZero<isize>
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.
ยงSafety
This results in undefined behavior when
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<NonZero<isize>>
pub const fn checked_pow(self, other: u32) -> Option<NonZero<isize>>
1.64.0 (const: 1.64.0) ยท Sourcepub const fn saturating_pow(self, other: u32) -> NonZero<isize>
pub const fn saturating_pow(self, other: u32) -> NonZero<isize>
Raise non-zero value to an integer power.
Return NonZero::<isize>::MIN or NonZero::<isize>::MAX on overflow.
ยงExamples
Sourcepub const fn from_ascii(src: &[u8]) -> Result<NonZero<isize>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii(src: &[u8]) -> Result<NonZero<isize>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with decimal digits.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<isize>::from_ascii(b"+10"), Ok(NonZero::new(10)?));Trailing space returns error:
Sourcepub const fn from_ascii_radix(
src: &[u8],
radix: u32,
) -> Result<NonZero<isize>, ParseIntError>
๐ฌThis is a nightly-only experimental API. (int_from_ascii #134821)
pub const fn from_ascii_radix( src: &[u8], radix: u32, ) -> Result<NonZero<isize>, ParseIntError>
int_from_ascii #134821)Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
The characters are expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
#![feature(int_from_ascii)]
assert_eq!(NonZero::<isize>::from_ascii_radix(b"A", 16), Ok(NonZero::new(10)?));Trailing space returns error:
1.98.0 (const: 1.98.0) ยท Sourcepub const fn from_str_radix(
src: &str,
radix: u32,
) -> Result<NonZero<isize>, ParseIntError>
pub const fn from_str_radix( src: &str, radix: u32, ) -> Result<NonZero<isize>, ParseIntError>
Parses a non-zero integer from a string slice with digits in a given base.
The string is expected to be an optional
+ or -
sign followed by only digits. Leading and trailing non-digit characters (including
whitespace) represent an error. Underscores (which are accepted in Rust literals)
also represent an error.
Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
ยงPanics
This method panics if radix is not in the range from 2 to 36.
ยงExamples
Trailing space returns error:
Trait Implementationsยง
1.45.0 (const: unstable) ยท Sourceยงimpl<T> BitOr for NonZero<T>where
T: ZeroablePrimitive + BitOr<Output = T>,
impl<T> BitOr for NonZero<T>where
T: ZeroablePrimitive + BitOr<Output = T>,
1.45.0 (const: unstable) ยท Sourceยงimpl<T> BitOr<NonZero<T>> for Twhere
T: ZeroablePrimitive + BitOr<Output = T>,
impl<T> BitOr<NonZero<T>> for Twhere
T: ZeroablePrimitive + BitOr<Output = T>,
1.45.0 (const: unstable) ยท Sourceยงimpl<T> BitOr<T> for NonZero<T>where
T: ZeroablePrimitive + BitOr<Output = T>,
impl<T> BitOr<T> for NonZero<T>where
T: ZeroablePrimitive + BitOr<Output = T>,
1.45.0 (const: unstable) ยท Sourceยงimpl<T> BitOrAssign for NonZero<T>
impl<T> BitOrAssign for NonZero<T>
Sourceยงfn bitor_assign(&mut self, rhs: NonZero<T>)
fn bitor_assign(&mut self, rhs: NonZero<T>)
|= operation. Read more1.45.0 (const: unstable) ยท Sourceยงimpl<T> BitOrAssign<T> for NonZero<T>
impl<T> BitOrAssign<T> for NonZero<T>
Sourceยงfn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
|= operation. Read moreimpl<T> Copy for NonZero<T>where
T: ZeroablePrimitive,
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<u8>> for u8
impl Div<NonZero<u8>> for u8
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<u16>> for u16
impl Div<NonZero<u16>> for u16
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<u32>> for u32
impl Div<NonZero<u32>> for u32
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<u64>> for u64
impl Div<NonZero<u64>> for u64
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<u128>> for u128
impl Div<NonZero<u128>> for u128
1.51.0 (const: unstable) ยท Sourceยงimpl Div<NonZero<usize>> for usize
impl Div<NonZero<usize>> for usize
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
1.79.0 (const: unstable) ยท 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>)
Same as self /= other.get(), but because other is a NonZero<_>,
thereโs never a runtime check for division-by-zero.
This operation rounds towards zero, truncating any fractional part of the exact result, and cannot panic.
impl<T> Eq for NonZero<T>where
T: ZeroablePrimitive + Eq,
impl<T> Freeze for NonZero<T>where
T: ZeroablePrimitive + Freeze,
1.28.0 (const: unstable) ยท Sourceยงimpl<T> Ord for NonZero<T>where
T: ZeroablePrimitive + Ord,
impl<T> Ord for NonZero<T>where
T: ZeroablePrimitive + Ord,
1.28.0 (const: unstable) ยท Sourceยงimpl<T> PartialEq for NonZero<T>where
T: ZeroablePrimitive + PartialEq,
impl<T> PartialEq for NonZero<T>where
T: ZeroablePrimitive + PartialEq,
1.28.0 (const: unstable) ยท Sourceยงimpl<T> PartialOrd for NonZero<T>where
T: ZeroablePrimitive + PartialOrd,
impl<T> PartialOrd for NonZero<T>where
T: ZeroablePrimitive + PartialOrd,
impl<T> RefUnwindSafe for NonZero<T>where
T: ZeroablePrimitive + RefUnwindSafe,
1.79.0 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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.
impl<T> Send for NonZero<T>where
T: ZeroablePrimitive + Send,
Sourceยงimpl Step for NonZero<u8>
impl Step for NonZero<u8>
Sourceยงunsafe fn forward_unchecked(start: NonZero<u8>, n: usize) -> NonZero<u8>
unsafe fn forward_unchecked(start: NonZero<u8>, n: usize) -> NonZero<u8>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<u8>, n: usize) -> NonZero<u8>
unsafe fn backward_unchecked(start: NonZero<u8>, n: usize) -> NonZero<u8>
step_trait #42168)Sourceยงfn forward(start: NonZero<u8>, n: usize) -> NonZero<u8>
fn forward(start: NonZero<u8>, n: usize) -> NonZero<u8>
step_trait #42168)Sourceยงfn backward(start: NonZero<u8>, n: usize) -> NonZero<u8>
fn backward(start: NonZero<u8>, n: usize) -> NonZero<u8>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<u8>,
end: &NonZero<u8>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<u8>, end: &NonZero<u8>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read moreSourceยงimpl Step for NonZero<u16>
impl Step for NonZero<u16>
Sourceยงunsafe fn forward_unchecked(start: NonZero<u16>, n: usize) -> NonZero<u16>
unsafe fn forward_unchecked(start: NonZero<u16>, n: usize) -> NonZero<u16>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<u16>, n: usize) -> NonZero<u16>
unsafe fn backward_unchecked(start: NonZero<u16>, n: usize) -> NonZero<u16>
step_trait #42168)Sourceยงfn forward(start: NonZero<u16>, n: usize) -> NonZero<u16>
fn forward(start: NonZero<u16>, n: usize) -> NonZero<u16>
step_trait #42168)Sourceยงfn backward(start: NonZero<u16>, n: usize) -> NonZero<u16>
fn backward(start: NonZero<u16>, n: usize) -> NonZero<u16>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<u16>,
end: &NonZero<u16>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<u16>, end: &NonZero<u16>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read moreSourceยงimpl Step for NonZero<u32>
impl Step for NonZero<u32>
Sourceยงunsafe fn forward_unchecked(start: NonZero<u32>, n: usize) -> NonZero<u32>
unsafe fn forward_unchecked(start: NonZero<u32>, n: usize) -> NonZero<u32>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<u32>, n: usize) -> NonZero<u32>
unsafe fn backward_unchecked(start: NonZero<u32>, n: usize) -> NonZero<u32>
step_trait #42168)Sourceยงfn forward(start: NonZero<u32>, n: usize) -> NonZero<u32>
fn forward(start: NonZero<u32>, n: usize) -> NonZero<u32>
step_trait #42168)Sourceยงfn backward(start: NonZero<u32>, n: usize) -> NonZero<u32>
fn backward(start: NonZero<u32>, n: usize) -> NonZero<u32>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<u32>,
end: &NonZero<u32>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<u32>, end: &NonZero<u32>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read moreSourceยงimpl Step for NonZero<u64>
impl Step for NonZero<u64>
Sourceยงunsafe fn forward_unchecked(start: NonZero<u64>, n: usize) -> NonZero<u64>
unsafe fn forward_unchecked(start: NonZero<u64>, n: usize) -> NonZero<u64>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<u64>, n: usize) -> NonZero<u64>
unsafe fn backward_unchecked(start: NonZero<u64>, n: usize) -> NonZero<u64>
step_trait #42168)Sourceยงfn forward(start: NonZero<u64>, n: usize) -> NonZero<u64>
fn forward(start: NonZero<u64>, n: usize) -> NonZero<u64>
step_trait #42168)Sourceยงfn backward(start: NonZero<u64>, n: usize) -> NonZero<u64>
fn backward(start: NonZero<u64>, n: usize) -> NonZero<u64>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<u64>,
end: &NonZero<u64>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<u64>, end: &NonZero<u64>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read moreSourceยงimpl Step for NonZero<usize>
impl Step for NonZero<usize>
Sourceยงunsafe fn forward_unchecked(start: NonZero<usize>, n: usize) -> NonZero<usize>
unsafe fn forward_unchecked(start: NonZero<usize>, n: usize) -> NonZero<usize>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<usize>, n: usize) -> NonZero<usize>
unsafe fn backward_unchecked(start: NonZero<usize>, n: usize) -> NonZero<usize>
step_trait #42168)Sourceยงfn forward(start: NonZero<usize>, n: usize) -> NonZero<usize>
fn forward(start: NonZero<usize>, n: usize) -> NonZero<usize>
step_trait #42168)Sourceยงfn backward(start: NonZero<usize>, n: usize) -> NonZero<usize>
fn backward(start: NonZero<usize>, n: usize) -> NonZero<usize>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<usize>,
end: &NonZero<usize>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<usize>, end: &NonZero<usize>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read moreSourceยงimpl Step for NonZero<u128>
impl Step for NonZero<u128>
Sourceยงunsafe fn forward_unchecked(start: NonZero<u128>, n: usize) -> NonZero<u128>
unsafe fn forward_unchecked(start: NonZero<u128>, n: usize) -> NonZero<u128>
step_trait #42168)Sourceยงunsafe fn backward_unchecked(start: NonZero<u128>, n: usize) -> NonZero<u128>
unsafe fn backward_unchecked(start: NonZero<u128>, n: usize) -> NonZero<u128>
step_trait #42168)Sourceยงfn forward(start: NonZero<u128>, n: usize) -> NonZero<u128>
fn forward(start: NonZero<u128>, n: usize) -> NonZero<u128>
step_trait #42168)Sourceยงfn backward(start: NonZero<u128>, n: usize) -> NonZero<u128>
fn backward(start: NonZero<u128>, n: usize) -> NonZero<u128>
step_trait #42168)Sourceยงfn steps_between(
start: &NonZero<u128>,
end: &NonZero<u128>,
) -> (usize, Option<usize>)
fn steps_between( start: &NonZero<u128>, end: &NonZero<u128>, ) -> (usize, Option<usize>)
step_trait #42168)start to end
like Iterator::size_hint(). Read more