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