pub struct NonValueU128<const V: u128>(/* private fields */);
Expand description
𝟙 ⚗️ An unsigned integer that is known not to equal some specific value.
It has the same memory layout optimization as NonZeroU128
,
so that Option<NonValueU128>
is the same size as NonValueU128
.
§Examples
assert![NonValueI8::<13>::new(13).is_none()];
assert![NonValueI8::<13>::new(12).unwrap().get() == 12];
See also NonExtremeU128
.
Implementations§
Source§impl<const V: u128> NonValueU128<V>
impl<const V: u128> NonValueU128<V>
Sourcepub const VALID_VALUES: u128 = 340_282_366_920_938_463_463_374_607_431_768_211_455u128
pub const VALID_VALUES: u128 = 340_282_366_920_938_463_463_374_607_431_768_211_455u128
Returns the number of valid values.
Sourcepub const INVALID_VALUES: u128 = 1u128
pub const INVALID_VALUES: u128 = 1u128
Returns the number of invalid values.
Sourcepub const fn new(value: u128) -> Option<Self> ⓘ
pub const fn new(value: u128) -> Option<Self> ⓘ
Returns a NonValueU128
with the given value
, if it is not equal to V
.
Sourcepub const fn new_lossy(value: u128) -> Self
pub const fn new_lossy(value: u128) -> Self
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];
Sourcepub const unsafe fn new_unchecked(value: u128) -> Self
pub const unsafe fn new_unchecked(value: u128) -> Self
Sourcepub const fn checked_add(&self, other: u128) -> NumResult<Self>
pub const fn checked_add(&self, other: u128) -> NumResult<Self>
Sourcepub const fn checked_sub(&self, other: u128) -> NumResult<Self>
pub const fn checked_sub(&self, other: u128) -> NumResult<Self>
Sourcepub const fn strict_add(&self, other: u128) -> Self
pub const fn strict_add(&self, other: u128) -> Self
Strict integer addition. Computes self + rhs
.
§Panics
Panics on overflow or if the result equals the forbidden value V
.
Sourcepub const fn strict_sub(&self, other: u128) -> Self
pub const fn strict_sub(&self, other: u128) -> Self
Strict integer substration. Computes self - rhs
.
§Panics
Panics on overflow or if the result equals the forbidden value V
.
Sourcepub const fn saturating_add(&self, other: u128) -> Self
pub const fn saturating_add(&self, other: u128) -> Self
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
.
Sourcepub const fn saturating_sub(&self, other: u128) -> Self
pub const fn saturating_sub(&self, other: u128) -> Self
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
.
Sourcepub const fn wrapping_add(&self, other: u128) -> Self
pub const fn wrapping_add(&self, other: u128) -> Self
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
.
Sourcepub const fn wrapping_sub(&self, other: u128) -> Self
pub const fn wrapping_sub(&self, other: u128) -> Self
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§
Source§impl<const V: u128> Binary for NonValueU128<V>
impl<const V: u128> Binary for NonValueU128<V>
Source§impl<const V: u128> BitSized<{$IP::BYTE_SIZE * 8}> for NonValueU128<V>
impl<const V: u128> BitSized<{$IP::BYTE_SIZE * 8}> for NonValueU128<V>
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<const V: u128> CheckedBitPattern for NonValueU128<V>
impl<const V: u128> CheckedBitPattern for NonValueU128<V>
Source§type Bits = u128
type Bits = u128
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.Source§fn is_valid_bit_pattern(bits: &Self::Bits) -> bool
fn is_valid_bit_pattern(bits: &Self::Bits) -> bool
bits
as &Self
.Source§impl<const V: u128> Clone for NonValueU128<V>
impl<const V: u128> Clone for NonValueU128<V>
Source§fn clone(&self) -> NonValueU128<V>
fn clone(&self) -> NonValueU128<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<const V: u128> Debug for NonValueU128<V>
impl<const V: u128> Debug for NonValueU128<V>
Source§impl<const V: u128> Display for NonValueU128<V>
impl<const V: u128> Display for NonValueU128<V>
Source§impl<const V: u128> From<NonValueU128<V>> for u128
impl<const V: u128> From<NonValueU128<V>> for u128
Source§fn from(value: NonValueU128<V>) -> u128
fn from(value: NonValueU128<V>) -> u128
Source§impl<const V: u128> FromStr for NonValueU128<V>
impl<const V: u128> FromStr for NonValueU128<V>
Source§impl<const V: u128> Hash for NonValueU128<V>
impl<const V: u128> Hash for NonValueU128<V>
Source§impl<const V: u128> LowerHex for NonValueU128<V>
impl<const V: u128> LowerHex for NonValueU128<V>
Source§impl<const V: u128> Octal for NonValueU128<V>
impl<const V: u128> Octal for NonValueU128<V>
Source§impl<const V: u128> Ord for NonValueU128<V>
impl<const V: u128> Ord for NonValueU128<V>
Source§fn cmp(&self, other: &NonValueU128<V>) -> Ordering
fn cmp(&self, other: &NonValueU128<V>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const V: u128> PartialEq for NonValueU128<V>
impl<const V: u128> PartialEq for NonValueU128<V>
Source§impl<const V: u128> PartialOrd for NonValueU128<V>
impl<const V: u128> PartialOrd for NonValueU128<V>
Source§impl<const V: u128> UpperHex for NonValueU128<V>
impl<const V: u128> UpperHex for NonValueU128<V>
impl<const V: u128> Copy for NonValueU128<V>
impl<const V: u128> Eq for NonValueU128<V>
impl<const V: u128> NoUninit for NonValueU128<V>
impl<const V: u128> PodInOption for NonValueU128<V>
impl<const V: u128> StructuralPartialEq for NonValueU128<V>
impl<const V: u128> ZeroableInOption for NonValueU128<V>
Auto Trait Implementations§
impl<const V: u128> Freeze for NonValueU128<V>
impl<const V: u128> RefUnwindSafe for NonValueU128<V>
impl<const V: u128> Send for NonValueU128<V>
impl<const V: u128> Sync for NonValueU128<V>
impl<const V: u128> Unpin for NonValueU128<V>
impl<const V: u128> UnwindSafe for NonValueU128<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]
Source§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.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<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> 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
Source§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