Struct NonValueI32
pub struct NonValueI32<const V: i32>(/* private fields */);
Expand description
𝟙 ⚗️ A signed integer that is known not to equal some specific value.
It has the same memory layout optimization as NonZeroI32
,
so that Option<NonValueI32>
is the same size as NonValueI32
.
§Examples
assert![NonValueI8::<13>::new(13).is_none()];
assert![NonValueI8::<13>::new(12).unwrap().get() == 12];
See also NonExtremeI32
.
Implementations§
§impl<const V: i32> NonValueI32<V>
impl<const V: i32> NonValueI32<V>
pub const MAX: NonValueI32<V>
pub const MAX: NonValueI32<V>
Returns the maximum possible value.
pub const MIN: NonValueI32<V>
pub const MIN: NonValueI32<V>
Returns the minimum possible value.
pub const VALID_VALUES: i32 = 2_147_483_647i32
pub const VALID_VALUES: i32 = 2_147_483_647i32
Returns the number of valid values.
pub const INVALID_VALUES: i32 = 1i32
pub const INVALID_VALUES: i32 = 1i32
Returns the number of invalid values.
pub const fn new(value: i32) -> Option<NonValueI32<V>> ⓘ
pub const fn new(value: i32) -> Option<NonValueI32<V>> ⓘ
Returns a NonValueI32
with the given value
, if it is not equal to V
.
pub const fn new_lossy(value: i32) -> NonValueI32<V>
pub const fn new_lossy(value: i32) -> NonValueI32<V>
Creates a non-value integer, automatically converting the prohibited value V
to the closest valid number (V-1
for most cases, V+1
for MIN
).
§Guarantees
- For unsigned
MAX
:V-1
→ stored as!(V-1)
- For signed
MIN
:V+1
→ stored as(V+1) ^ MIN
- All others:
V-1
→ stored as(V-1) ^ V
§Features
- Can use the
unsafe_niche
feature internally.
§Example
let x = assert_eq![NonValueU8::<255>::new_lossy(255).get(), 254];
let y = assert_eq![NonValueI8::<-128>::new_lossy(-128).get(), -127];
pub const unsafe fn new_unchecked(value: i32) -> NonValueI32<V>
pub const unsafe fn new_unchecked(value: i32) -> NonValueI32<V>
pub const fn checked_add(
&self,
other: i32,
) -> Result<NonValueI32<V>, NicheValueError> ⓘ
pub const fn checked_add( &self, other: i32, ) -> Result<NonValueI32<V>, NicheValueError> ⓘ
Checked integer addition. Computes self + rhs
.
§Errors
Returns Overflow
if the operations overflows, or
InvalidValue
if the result equals the forbidden value V
.
pub const fn checked_sub(
&self,
other: i32,
) -> Result<NonValueI32<V>, NicheValueError> ⓘ
pub const fn checked_sub( &self, other: i32, ) -> Result<NonValueI32<V>, NicheValueError> ⓘ
Checked integer substration. Computes self - rhs
.
§Errors
Returns Overflow
if the operations overflows, or
InvalidValue
if the result equals the forbidden value V
.
pub const fn strict_add(&self, other: i32) -> NonValueI32<V>
pub const fn strict_add(&self, other: i32) -> NonValueI32<V>
Strict integer addition. Computes self + rhs
.
§Panics
Panics on overflow or if the result equals the forbidden value V
.
pub const fn strict_sub(&self, other: i32) -> NonValueI32<V>
pub const fn strict_sub(&self, other: i32) -> NonValueI32<V>
Strict integer substration. Computes self - rhs
.
§Panics
Panics on overflow or if the result equals the forbidden value V
.
pub const fn saturating_add(&self, other: i32) -> NonValueI32<V>
pub const fn saturating_add(&self, other: i32) -> NonValueI32<V>
Saturating integer addition. Computes self + rhs
.
Saturates at the numeric bounds instead of overflowing.
If the result would equal V
it will return V - 1
.
pub const fn saturating_sub(&self, other: i32) -> NonValueI32<V>
pub const fn saturating_sub(&self, other: i32) -> NonValueI32<V>
Saturating integer substration. Computes self - rhs
.
Saturates at the numeric bounds instead of overflowing.
If the result would equal V
it will return V + 1
.
pub const fn wrapping_add(&self, other: i32) -> NonValueI32<V>
pub const fn wrapping_add(&self, other: i32) -> NonValueI32<V>
Wraping integer addition. Computes self + rhs
.
Wraps at the numeric bounds instead of overflowing.
If the result would equal V
it will return V + 1
.
pub const fn wrapping_sub(&self, other: i32) -> NonValueI32<V>
pub const fn wrapping_sub(&self, other: i32) -> NonValueI32<V>
Wraping integer subtraction. Computes self - rhs
.
Wraps at the numeric bounds instead of overflowing.
If the result would equal V
it will return V - 1
.
Trait Implementations§
§impl<const V: i32> Binary for NonValueI32<V>
impl<const V: i32> Binary for NonValueI32<V>
Source§impl<const V: i32> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueI32<V>
impl<const V: i32> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueI32<V>
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
§impl<const V: i32> Clone for NonValueI32<V>
impl<const V: i32> Clone for NonValueI32<V>
§fn clone(&self) -> NonValueI32<V>
fn clone(&self) -> NonValueI32<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<const V: i32> Debug for NonValueI32<V>
impl<const V: i32> Debug for NonValueI32<V>
§impl Default for NonValueI32<devela_base_core::::num::niche::mem::non_value::__impls_NonValueI32::NonExtremeI32::{constant#0}>
impl Default for NonValueI32<devela_base_core::::num::niche::mem::non_value::__impls_NonValueI32::NonExtremeI32::{constant#0}>
§fn default() -> NonValueI32<devela_base_core::::num::niche::mem::non_value::__impls_NonValueI32::NonExtremeI32::{constant#0}>
fn default() -> NonValueI32<devela_base_core::::num::niche::mem::non_value::__impls_NonValueI32::NonExtremeI32::{constant#0}>
§Features
Makes use of the unsafe_niche
feature if enabled.
§impl<const V: i32> Display for NonValueI32<V>
impl<const V: i32> Display for NonValueI32<V>
§impl<const V: i32> From<NonValueI32<V>> for i32
impl<const V: i32> From<NonValueI32<V>> for i32
§fn from(value: NonValueI32<V>) -> i32 ⓘ
fn from(value: NonValueI32<V>) -> i32 ⓘ
§impl<const V: i32> FromStr for NonValueI32<V>
impl<const V: i32> FromStr for NonValueI32<V>
§type Err = ParseIntError
type Err = ParseIntError
§fn from_str(s: &str) -> Result<NonValueI32<V>, <NonValueI32<V> as FromStr>::Err> ⓘ
fn from_str(s: &str) -> Result<NonValueI32<V>, <NonValueI32<V> as FromStr>::Err> ⓘ
s
to return a value of this type. Read more§impl<const V: i32> Hash for NonValueI32<V>
impl<const V: i32> Hash for NonValueI32<V>
§impl<const V: i32> LowerHex for NonValueI32<V>
impl<const V: i32> LowerHex for NonValueI32<V>
§impl<const V: i32> Octal for NonValueI32<V>
impl<const V: i32> Octal for NonValueI32<V>
§impl<const V: i32> Ord for NonValueI32<V>
impl<const V: i32> Ord for NonValueI32<V>
§impl<const V: i32> PartialEq for NonValueI32<V>
impl<const V: i32> PartialEq for NonValueI32<V>
§impl<const V: i32> PartialOrd for NonValueI32<V>
impl<const V: i32> PartialOrd for NonValueI32<V>
§impl<const V: i32> TryFrom<i32> for NonValueI32<V>
impl<const V: i32> TryFrom<i32> for NonValueI32<V>
§fn try_from(
value: i32,
) -> Result<NonValueI32<V>, <NonValueI32<V> as TryFrom<i32>>::Error> ⓘ
fn try_from( value: i32, ) -> Result<NonValueI32<V>, <NonValueI32<V> as TryFrom<i32>>::Error> ⓘ
§Features
Makes use of the unsafe_niche
feature if enabled.
§type Error = TryFromIntError
type Error = TryFromIntError
§impl<const V: i32> UpperHex for NonValueI32<V>
impl<const V: i32> UpperHex for NonValueI32<V>
impl<const V: i32> Copy for NonValueI32<V>
impl<const V: i32> Eq for NonValueI32<V>
impl<const V: i32> StructuralPartialEq for NonValueI32<V>
Auto Trait Implementations§
impl<const V: i32> Freeze for NonValueI32<V>
impl<const V: i32> RefUnwindSafe for NonValueI32<V>
impl<const V: i32> UnwindSafe for NonValueI32<V>
impl<const V: i32> Send for NonValueI32<V>
impl<const V: i32> Sync for NonValueI32<V>
impl<const V: i32> Unpin for NonValueI32<V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64 ⓘ
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64 ⓘ
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Hook for T
impl<T> Hook for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more