pub type NonZeroIsize = NonZero<isize>;Expand description
⅀ ⚗️
core
A signed integer that is known not to equal zero.
📍num/grain/niche re-exported from core::num
📜
An isize that is known not to equal zero.
This enables some memory layout optimization.
For example, Option<NonZeroIsize> is the same size as isize:
assert_eq!(size_of::<Option<core::num::NonZeroIsize>>(), size_of::<isize>());§Layout
NonZeroIsize is guaranteed to have the same layout and bit validity as isize
with the exception that 0 is not a valid instance.
Option<NonZeroIsize> is guaranteed to be compatible with isize,
including in FFI.
Thanks to the null pointer optimization,
NonZeroIsize and Option<NonZeroIsize>
are guaranteed to have the same size and alignment:
use std::num::NonZeroIsize;
assert_eq!(size_of::<NonZeroIsize>(), size_of::<Option<NonZeroIsize>>());
assert_eq!(align_of::<NonZeroIsize>(), align_of::<Option<NonZeroIsize>>());§Compile-time creation
Since both Option::unwrap() and Option::expect() are const, it is possible to
define a new
NonZeroIsize
at compile time via:
use std::num::NonZeroIsize;
const TEN: NonZeroIsize = NonZeroIsize::new(10).expect("ten is non-zero");Aliased Type§
pub struct NonZeroIsize(/* private fields */);Trait Implementations§
Source§impl BitSized<64> for NonZeroIsize
impl BitSized<64> for NonZeroIsize
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
Source§fn bit_size(&self) -> usize
fn bit_size(&self) -> usize
Source§fn min_byte_size(&self) -> usize
fn min_byte_size(&self) -> usize
Source§impl ConstInit for NonZeroIsize
This implementation returns the same as Self::MIN.
impl ConstInit for NonZeroIsize
This implementation returns the same as Self::MIN.
Source§impl Num for NonZeroIsize
impl Num for NonZeroIsize
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>
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<()>
self to the given valid &value.Source§fn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
true if self is zero.Source§fn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
true if self is one.Source§fn num_get_zero() -> Result<Self>
fn num_get_zero() -> Result<Self>
Source§fn num_get_one() -> Result<Self>
fn num_get_one() -> Result<Self>
Source§fn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
self to 0.Source§fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
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<()>
&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>
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<()>
&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>
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<()>
&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>
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<()>
&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>
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<()>
&mut self %= rhs; (remainder).Source§impl NumConst for NonZeroIsize
impl NumConst for NonZeroIsize
Source§const NUM_IS_BIG: bool = false
const NUM_IS_BIG: bool = false
Source§const NUM_IS_INT: bool = true
const NUM_IS_INT: bool = true
Source§const NUM_IS_FLOAT: bool = false
const NUM_IS_FLOAT: bool = false
Source§const NUM_IS_FIXED: bool = false
const NUM_IS_FIXED: bool = false
Source§const NUM_IS_SIGNED: bool = true
const NUM_IS_SIGNED: bool = true
Source§const NUM_IS_NICHE: bool = true
const NUM_IS_NICHE: bool = true
Source§const NUM_ZERO: Option<NonZeroIsize>
const NUM_ZERO: Option<NonZeroIsize>
0), if applicable.Source§const NUM_ONE: Option<NonZeroIsize>
const NUM_ONE: Option<NonZeroIsize>
1).Source§const NUM_TWO: Option<NonZeroIsize>
const NUM_TWO: Option<NonZeroIsize>
2).Source§const NUM_THREE: Option<NonZeroIsize>
const NUM_THREE: Option<NonZeroIsize>
3).Source§const NUM_NEG_ONE: Option<NonZeroIsize>
const NUM_NEG_ONE: Option<NonZeroIsize>
ONE (-1), if applicable.Source§const NUM_MIN: Option<NonZeroIsize>
const NUM_MIN: Option<NonZeroIsize>
Source§const NUM_MAX: Option<NonZeroIsize>
const NUM_MAX: Option<NonZeroIsize>
Source§const NUM_MIN_POSITIVE: Option<NonZeroIsize>
const NUM_MIN_POSITIVE: Option<NonZeroIsize>
Source§const NUM_MAX_NEGATIVE: Option<NonZeroIsize>
const NUM_MAX_NEGATIVE: Option<NonZeroIsize>
Source§const NUM_MIN_NORM: Option<NonZeroIsize>
const NUM_MIN_NORM: Option<NonZeroIsize>
MIN for integers).Source§const NUM_MAX_NORM: Option<NonZeroIsize>
const NUM_MAX_NORM: Option<NonZeroIsize>
MAX for integers).Source§const NUM_MAX_POWER_OF_TWO: Option<NonZeroIsize>
const NUM_MAX_POWER_OF_TWO: Option<NonZeroIsize>
Source§fn is_num_zero(&self) -> bool
fn is_num_zero(&self) -> bool
self is equal to NUM_ZERO.Source§fn is_num_one(&self) -> bool
fn is_num_one(&self) -> bool
self is equal to NUM_ONE.Source§fn is_num_two(&self) -> bool
fn is_num_two(&self) -> bool
self is equal to NUM_TWO.Source§fn is_num_three(&self) -> bool
fn is_num_three(&self) -> bool
self is equal to NUM_THREE.Source§fn is_num_neg_one(&self) -> bool
fn is_num_neg_one(&self) -> bool
self is equal to NUM_NEG_ONE.Source§fn is_num_min(&self) -> bool
fn is_num_min(&self) -> bool
self is equal to NUM_MIN.Source§fn is_num_max(&self) -> bool
fn is_num_max(&self) -> bool
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
self is equal to NUM_MAX_NEGATIVE.Source§fn is_num_min_norm(&self) -> bool
fn is_num_min_norm(&self) -> bool
self is equal to NUM_MIN_NORM.Source§fn is_num_max_norm(&self) -> bool
fn is_num_max_norm(&self) -> bool
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
self is equal to NUM_MAX_POWER_OF_TWO.