Struct NonValueU64
pub struct NonValueU64<const V: u64>(/* private fields */);
Expand description
𝟙 ⚗️ An unsigned integer that is known not to equal some specific value.
It has the same memory layout optimization as NonZeroU64
,
so that Option<NonValueU64>
is the same size as NonValueU64
.
§Examples
assert![NonValueI8::<13>::new(13).is_none()];
assert![NonValueI8::<13>::new(12).unwrap().get() == 12];
See also NonExtremeU64
.
Implementations§
§impl<const V: u64> NonValueU64<V>
impl<const V: u64> NonValueU64<V>
pub const MAX: NonValueU64<V>
pub const MAX: NonValueU64<V>
Returns the maximum possible value.
pub const MIN: NonValueU64<V>
pub const MIN: NonValueU64<V>
Returns the minimum possible value.
pub const VALID_VALUES: u64 = 18_446_744_073_709_551_615u64
pub const VALID_VALUES: u64 = 18_446_744_073_709_551_615u64
Returns the number of valid values.
pub const INVALID_VALUES: u64 = 1u64
pub const INVALID_VALUES: u64 = 1u64
Returns the number of invalid values.
pub const fn new(value: u64) -> Option<NonValueU64<V>> ⓘ
pub const fn new(value: u64) -> Option<NonValueU64<V>> ⓘ
Returns a NonValueU64
with the given value
, if it is not equal to V
.
pub const fn new_lossy(value: u64) -> NonValueU64<V>
pub const fn new_lossy(value: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const unsafe fn new_unchecked(value: u64) -> NonValueU64<V>
pub const fn checked_add(
&self,
other: u64,
) -> Result<NonValueU64<V>, NicheValueError> ⓘ
pub const fn checked_add( &self, other: u64, ) -> Result<NonValueU64<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: u64,
) -> Result<NonValueU64<V>, NicheValueError> ⓘ
pub const fn checked_sub( &self, other: u64, ) -> Result<NonValueU64<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: u64) -> NonValueU64<V>
pub const fn strict_add(&self, other: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const fn strict_sub(&self, other: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const fn saturating_add(&self, other: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const fn saturating_sub(&self, other: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const fn wrapping_add(&self, other: u64) -> NonValueU64<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: u64) -> NonValueU64<V>
pub const fn wrapping_sub(&self, other: u64) -> NonValueU64<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: u64> Binary for NonValueU64<V>
impl<const V: u64> Binary for NonValueU64<V>
Source§impl<const V: u64> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueU64<V>
impl<const V: u64> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueU64<V>
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
§impl<const V: u64> Clone for NonValueU64<V>
impl<const V: u64> Clone for NonValueU64<V>
§fn clone(&self) -> NonValueU64<V>
fn clone(&self) -> NonValueU64<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: u64> Debug for NonValueU64<V>
impl<const V: u64> Debug for NonValueU64<V>
§impl Default for NonValueU64<devela_base_core::::num::niche::mem::non_value::__impls_NonValueU64::NonExtremeU64::{constant#0}>
impl Default for NonValueU64<devela_base_core::::num::niche::mem::non_value::__impls_NonValueU64::NonExtremeU64::{constant#0}>
§fn default() -> NonValueU64<devela_base_core::::num::niche::mem::non_value::__impls_NonValueU64::NonExtremeU64::{constant#0}>
fn default() -> NonValueU64<devela_base_core::::num::niche::mem::non_value::__impls_NonValueU64::NonExtremeU64::{constant#0}>
§Features
Makes use of the unsafe_niche
feature if enabled.
§impl<const V: u64> Display for NonValueU64<V>
impl<const V: u64> Display for NonValueU64<V>
§impl<const V: u64> From<NonValueU64<V>> for u64
impl<const V: u64> From<NonValueU64<V>> for u64
§fn from(value: NonValueU64<V>) -> u64 ⓘ
fn from(value: NonValueU64<V>) -> u64 ⓘ
§impl<const V: u64> FromStr for NonValueU64<V>
impl<const V: u64> FromStr for NonValueU64<V>
§type Err = ParseIntError
type Err = ParseIntError
§fn from_str(s: &str) -> Result<NonValueU64<V>, <NonValueU64<V> as FromStr>::Err> ⓘ
fn from_str(s: &str) -> Result<NonValueU64<V>, <NonValueU64<V> as FromStr>::Err> ⓘ
s
to return a value of this type. Read more§impl<const V: u64> Hash for NonValueU64<V>
impl<const V: u64> Hash for NonValueU64<V>
§impl<const V: u64> LowerHex for NonValueU64<V>
impl<const V: u64> LowerHex for NonValueU64<V>
§impl<const V: u64> Octal for NonValueU64<V>
impl<const V: u64> Octal for NonValueU64<V>
§impl<const V: u64> Ord for NonValueU64<V>
impl<const V: u64> Ord for NonValueU64<V>
§impl<const V: u64> PartialEq for NonValueU64<V>
impl<const V: u64> PartialEq for NonValueU64<V>
§impl<const V: u64> PartialOrd for NonValueU64<V>
impl<const V: u64> PartialOrd for NonValueU64<V>
§impl<const V: u64> TryFrom<u64> for NonValueU64<V>
impl<const V: u64> TryFrom<u64> for NonValueU64<V>
§fn try_from(
value: u64,
) -> Result<NonValueU64<V>, <NonValueU64<V> as TryFrom<u64>>::Error> ⓘ
fn try_from( value: u64, ) -> Result<NonValueU64<V>, <NonValueU64<V> as TryFrom<u64>>::Error> ⓘ
§Features
Makes use of the unsafe_niche
feature if enabled.
§type Error = TryFromIntError
type Error = TryFromIntError
§impl<const V: u64> UpperHex for NonValueU64<V>
impl<const V: u64> UpperHex for NonValueU64<V>
impl<const V: u64> Copy for NonValueU64<V>
impl<const V: u64> Eq for NonValueU64<V>
impl<const V: u64> StructuralPartialEq for NonValueU64<V>
Auto Trait Implementations§
impl<const V: u64> Freeze for NonValueU64<V>
impl<const V: u64> RefUnwindSafe for NonValueU64<V>
impl<const V: u64> UnwindSafe for NonValueU64<V>
impl<const V: u64> Send for NonValueU64<V>
impl<const V: u64> Sync for NonValueU64<V>
impl<const V: u64> Unpin for NonValueU64<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