pub struct NonValueU32<const V: u32>(/* private fields */);Expand description
⅀ ⚗️ An unsigned integer that is known not to equal some specific value.
It has the same memory layout optimization as NonZero<u32>, so that Option<NonValueU32> is the same size as NonValueU32.
§Examples
assert![NonValueI8::<13>::new(13).is_none()];
assert![NonValueI8::<13>::new(12).unwrap().get() == 12];See also NonMaxU32.
Implementations§
Source§impl<const V: u32> NonValueU32<V>
impl<const V: u32> NonValueU32<V>
Sourcepub const VALID_VALUES: u32 = u32::MAX
pub const VALID_VALUES: u32 = u32::MAX
Returns the number of valid values.
Sourcepub const INVALID_VALUES: u32 = 1
pub const INVALID_VALUES: u32 = 1
Returns the number of invalid values.
Sourcepub const fn new(value: u32) -> Option<Self> ⓘ
pub const fn new(value: u32) -> Option<Self> ⓘ
Returns a NonValueU32 with the given value, if it is not equal to V.
Sourcepub const fn new_lossy(value: u32) -> Self
pub const fn new_lossy(value: u32) -> 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_nichefeature internally.
§Examples
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: u32) -> Self
Available on crate feature unsafe_niche only.
pub const unsafe fn new_unchecked(value: u32) -> Self
unsafe_niche only.Sourcepub const fn checked_add(&self, other: u32) -> Result<Self, NicheValueError> ⓘ
pub const fn checked_add(&self, other: u32) -> Result<Self, NicheValueError> ⓘ
Checked integer addition. Computes self + rhs.
§Errors
Returns Overflow if the operations overflows, or
InvalidValue if the result equals the forbidden value V.
Sourcepub const fn checked_sub(&self, other: u32) -> Result<Self, NicheValueError> ⓘ
pub const fn checked_sub(&self, other: u32) -> Result<Self, NicheValueError> ⓘ
Checked integer substration. Computes self - rhs.
§Errors
Returns Overflow if the operations overflows, or
InvalidValue if the result equals the forbidden value V.
Sourcepub const fn strict_add(&self, other: u32) -> Self
pub const fn strict_add(&self, other: u32) -> 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: u32) -> Self
pub const fn strict_sub(&self, other: u32) -> 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: u32) -> Self
pub const fn saturating_add(&self, other: u32) -> 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: u32) -> Self
pub const fn saturating_sub(&self, other: u32) -> 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: u32) -> Self
pub const fn wrapping_add(&self, other: u32) -> 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: u32) -> Self
pub const fn wrapping_sub(&self, other: u32) -> 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: u32> Binary for NonValueU32<V>
impl<const V: u32> Binary for NonValueU32<V>
Source§impl<const V: u32> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueU32<V>
impl<const V: u32> BitSized<{<$IP>::BYTE_SIZE * 8}> for NonValueU32<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: u32> Clone for NonValueU32<V>
impl<const V: u32> Clone for NonValueU32<V>
Source§fn clone(&self) -> NonValueU32<V>
fn clone(&self) -> NonValueU32<V>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const V: u32> ConstInit for NonValueU32<V>
impl<const V: u32> ConstInit for NonValueU32<V>
impl<const V: u32> Copy for NonValueU32<V>
Source§impl<const V: u32> Debug for NonValueU32<V>
impl<const V: u32> Debug for NonValueU32<V>
Source§impl<const V: u32> Display for NonValueU32<V>
impl<const V: u32> Display for NonValueU32<V>
impl<const V: u32> Eq for NonValueU32<V>
Source§impl<const V: u32> From<NonValueU32<V>> for u32
impl<const V: u32> From<NonValueU32<V>> for u32
Source§fn from(value: NonValueU32<V>) -> u32
fn from(value: NonValueU32<V>) -> u32
Source§impl<const V: u32> FromStr for NonValueU32<V>
impl<const V: u32> FromStr for NonValueU32<V>
Source§impl<const V: u32> Hash for NonValueU32<V>
impl<const V: u32> Hash for NonValueU32<V>
Source§impl<const V: u32> LowerHex for NonValueU32<V>
impl<const V: u32> LowerHex for NonValueU32<V>
Source§impl<const V: u32> Octal for NonValueU32<V>
impl<const V: u32> Octal for NonValueU32<V>
Source§impl<const V: u32> Ord for NonValueU32<V>
impl<const V: u32> Ord for NonValueU32<V>
Source§fn cmp(&self, other: &NonValueU32<V>) -> Ordering
fn cmp(&self, other: &NonValueU32<V>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const V: u32> PartialEq for NonValueU32<V>
impl<const V: u32> PartialEq for NonValueU32<V>
Source§fn eq(&self, other: &NonValueU32<V>) -> bool
fn eq(&self, other: &NonValueU32<V>) -> bool
self and other values to be equal, and is used by ==.Source§impl<const V: u32> PartialOrd for NonValueU32<V>
impl<const V: u32> PartialOrd for NonValueU32<V>
impl<const V: u32> StructuralPartialEq for NonValueU32<V>
Auto Trait Implementations§
impl<const V: u32> Freeze for NonValueU32<V>
impl<const V: u32> RefUnwindSafe for NonValueU32<V>
impl<const V: u32> Send for NonValueU32<V>
impl<const V: u32> Sync for NonValueU32<V>
impl<const V: u32> Unpin for NonValueU32<V>
impl<const V: u32> UnsafeUnpin for NonValueU32<V>
impl<const V: u32> UnwindSafe for NonValueU32<V>
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt 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§fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> MemExt for Twhere
T: ?Sized,
impl<T> MemExt 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.