pub type NonZeroI32 = NonZero<i32>;
Expand description
core
A signed integer that is known not to equal zero.
Re-exported from core
::num::
.
An i32
that is known not to equal zero.
This enables some memory layout optimization.
For example, Option<NonZeroI32>
is the same size as i32
:
use std::mem::size_of;
assert_eq!(size_of::<Option<core::num::NonZeroI32>>(), size_of::<i32>());
§Layout
NonZeroI32
is guaranteed to have the same layout and bit validity as i32
with the exception that 0
is not a valid instance.
Option<NonZeroI32>
is guaranteed to be compatible with i32
,
including in FFI.
Thanks to the null pointer optimization,
NonZeroI32
and Option<NonZeroI32>
are guaranteed to have the same size and alignment:
use std::num::NonZeroI32;
assert_eq!(size_of::<NonZeroI32>(), size_of::<Option<NonZeroI32>>());
assert_eq!(align_of::<NonZeroI32>(), align_of::<Option<NonZeroI32>>());
Aliased Type§
struct NonZeroI32(/* private fields */);
Trait Implementations§
Source§impl BitSized<32> for NonZeroI32
impl BitSized<32> for NonZeroI32
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 NonZeroI32
Available on crate feature _int_i32
only.
impl Num for NonZeroI32
Available on crate feature
_int_i32
only.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).