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