pub type NonZeroUsize = NonZero<usize>;
Expand description
𝟙 ⚗️
core
An unsigned integer that is known not to equal zero.
Re-exported from core
::num::
.
A usize
that is known not to equal zero.
This enables some memory layout optimization.
For example, Option<NonZeroUsize>
is the same size as usize
:
assert_eq!(size_of::<Option<core::num::NonZeroUsize>>(), size_of::<usize>());
§Layout
NonZeroUsize
is guaranteed to have the same layout and bit validity as usize
with the exception that 0
is not a valid instance.
Option<NonZeroUsize>
is guaranteed to be compatible with usize
,
including in FFI.
Thanks to the null pointer optimization,
NonZeroUsize
and Option<NonZeroUsize>
are guaranteed to have the same size and alignment:
use std::num::NonZeroUsize;
assert_eq!(size_of::<NonZeroUsize>(), size_of::<Option<NonZeroUsize>>());
assert_eq!(align_of::<NonZeroUsize>(), align_of::<Option<NonZeroUsize>>());
Aliased Type§
pub struct NonZeroUsize(/* private fields */);
Trait Implementations§
Source§impl BitSized<64> for NonZeroUsize
impl BitSized<64> for NonZeroUsize
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
The bit size of this type (only the relevant data part, without padding). Read more
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
The rounded up byte size for this type. Read more
Source§impl Num for NonZeroUsize
impl Num for NonZeroUsize
Source§fn num_set_one(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
§Features
Makes use of the unsafe_niche
feature if enabled.
Source§fn num_from_ref(from: &Self::Inner) -> Result<Self>
fn num_from_ref(from: &Self::Inner) -> Result<Self>
Returns
Self
if given a valid &value
.Source§fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
Sets
self
to the given valid &value
.Source§fn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
Returns
true
if self
is zero.Source§fn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
Returns
true
if self
is one.Source§fn num_get_zero() -> Result<Self>
fn num_get_zero() -> Result<Self>
Returns the number zero.
Source§fn num_get_one() -> Result<Self>
fn num_get_one() -> Result<Self>
Returns the number one.
Source§fn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
Sets
self
to 0
.Source§fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
Like
num_mul
but takes the arguments by reference.Source§fn num_ref_mul_assign(&mut self, other: &Self) -> Result<()>
fn num_ref_mul_assign(&mut self, other: &Self) -> Result<()>
Computes
&mut self *= rhs;
(multiplication).Source§fn num_ref_add(&self, other: &Self) -> Result<Self::Out>
fn num_ref_add(&self, other: &Self) -> Result<Self::Out>
Like
num_add
but takes the arguments by reference.Source§fn num_ref_add_assign(&mut self, other: &Self) -> Result<()>
fn num_ref_add_assign(&mut self, other: &Self) -> Result<()>
Computes
&mut self += rhs;
(addition).Source§fn num_ref_sub(&self, other: &Self) -> Result<Self::Out>
fn num_ref_sub(&self, other: &Self) -> Result<Self::Out>
Like
num_sub
but takes the arguments by reference.Source§fn num_ref_sub_assign(&mut self, other: &Self) -> Result<()>
fn num_ref_sub_assign(&mut self, other: &Self) -> Result<()>
Computes
&mut self -= rhs;
(subtraction).Source§fn num_ref_div(&self, other: &Self) -> Result<Self::Out>
fn num_ref_div(&self, other: &Self) -> Result<Self::Out>
Like
num_div
but takes the arguments by reference.Source§fn num_ref_div_assign(&mut self, other: &Self) -> Result<()>
fn num_ref_div_assign(&mut self, other: &Self) -> Result<()>
Computes
&mut self /= rhs;
(division).Source§fn num_ref_rem(&self, other: &Self) -> Result<Self::Out>
fn num_ref_rem(&self, other: &Self) -> Result<Self::Out>
Like
num_rem
but takes the arguments by reference.Source§fn num_ref_rem_assign(&mut self, other: &Self) -> Result<()>
fn num_ref_rem_assign(&mut self, other: &Self) -> Result<()>
Computes
&mut self %= rhs;
(remainder).Source§fn num_ref_abs(&self) -> Result<Self>
fn num_ref_abs(&self) -> Result<Self>
Like
num_abs
but takes the arguments by reference.Source§impl NumConst for NonZeroUsize
impl NumConst for NonZeroUsize
Source§const NUM_IS_BIG: bool = false
const NUM_IS_BIG: bool = false
Whether the number can represent big quantities.
Source§const NUM_IS_INT: bool = true
const NUM_IS_INT: bool = true
Whether the number uses an integer representation.
Source§const NUM_IS_FLOAT: bool = false
const NUM_IS_FLOAT: bool = false
Whether the number uses a floating-point representation.
Source§const NUM_IS_FIXED: bool = false
const NUM_IS_FIXED: bool = false
Whether the number uses a fixed-point representation.
Source§const NUM_IS_SIGNED: bool = false
const NUM_IS_SIGNED: bool = false
Whether the number includes the sign.
Source§const NUM_IS_NICHE: bool = true
const NUM_IS_NICHE: bool = true
Whether the number has a memory niche optimization.
Source§const NUM_ZERO: Option<NonZeroUsize>
const NUM_ZERO: Option<NonZeroUsize>
The additive identity (
0
), if applicable.Source§const NUM_ONE: Option<NonZeroUsize>
const NUM_ONE: Option<NonZeroUsize>
The multiplicative identity (
1
).Source§const NUM_TWO: Option<NonZeroUsize>
const NUM_TWO: Option<NonZeroUsize>
The only even prime and the fundamental doubling factor (
2
).Source§const NUM_THREE: Option<NonZeroUsize>
const NUM_THREE: Option<NonZeroUsize>
The smallest odd prime and the first nontrivial divisor (
3
).Source§const NUM_NEG_ONE: Option<NonZeroUsize> = None
const NUM_NEG_ONE: Option<NonZeroUsize> = None
The additive inverse of
ONE
(-1
), if applicable.Source§const NUM_MIN: Option<NonZeroUsize>
const NUM_MIN: Option<NonZeroUsize>
The smallest representable value.
Source§const NUM_MAX: Option<NonZeroUsize>
const NUM_MAX: Option<NonZeroUsize>
The greatest representable value.
Source§const NUM_MIN_POSITIVE: Option<NonZeroUsize>
const NUM_MIN_POSITIVE: Option<NonZeroUsize>
The smallest representable positive value.
Source§const NUM_MAX_NEGATIVE: Option<NonZeroUsize> = None
const NUM_MAX_NEGATIVE: Option<NonZeroUsize> = None
The greatest representable negative value, if applicable.
Source§const NUM_MIN_NORM: Option<NonZeroUsize>
const NUM_MIN_NORM: Option<NonZeroUsize>
The smallest normalized value (e.g. 0.0 for float,
MIN
for integers).Source§const NUM_MAX_NORM: Option<NonZeroUsize>
const NUM_MAX_NORM: Option<NonZeroUsize>
The greatest normalized value (e.g. 1.0 for float,
MAX
for integers).Source§const NUM_MAX_POWER_OF_TWO: Option<NonZeroUsize>
const NUM_MAX_POWER_OF_TWO: Option<NonZeroUsize>
The maximum representable power of two within the type’s range. Read more
Source§fn is_num_zero(&self) -> bool
fn is_num_zero(&self) -> bool
Whether
self
is equal to NUM_ZERO
.Source§fn is_num_one(&self) -> bool
fn is_num_one(&self) -> bool
Whether
self
is equal to NUM_ONE
.Source§fn is_num_two(&self) -> bool
fn is_num_two(&self) -> bool
Whether
self
is equal to NUM_TWO
.Source§fn is_num_three(&self) -> bool
fn is_num_three(&self) -> bool
Whether
self
is equal to NUM_THREE
.Source§fn is_num_neg_one(&self) -> bool
fn is_num_neg_one(&self) -> bool
Whether
self
is equal to NUM_NEG_ONE
.Source§fn is_num_min(&self) -> bool
fn is_num_min(&self) -> bool
Whether
self
is equal to NUM_MIN
.Source§fn is_num_max(&self) -> bool
fn is_num_max(&self) -> bool
Whether
self
is equal to NUM_MAX
.Source§fn is_num_min_positive(&self) -> bool
fn is_num_min_positive(&self) -> bool
Source§fn is_num_max_negative(&self) -> bool
fn is_num_max_negative(&self) -> bool
Whether
self
is equal to NUM_MAX_NEGATIVE
.Source§fn is_num_min_norm(&self) -> bool
fn is_num_min_norm(&self) -> bool
Whether
self
is equal to NUM_MIN_NORM
.Source§fn is_num_max_norm(&self) -> bool
fn is_num_max_norm(&self) -> bool
Whether
self
is equal to NUM_MAX_NORM
.Source§fn is_num_max_power_of_two(&self) -> bool
fn is_num_max_power_of_two(&self) -> bool
Whether
self
is equal to NUM_MAX_POWER_OF_TWO
.