pub type NonExtremeI8 = NonValueI8<{ i8::MIN }>;
Expand description
𝟙
⚗️
A signed integer that is known not to equal its most extreme value (MIN
).
Unlike the NonValue*
types in general, this type alias implements
the Default
and ConstDefault
traits.
Aliased Type§
pub struct NonExtremeI8(/* private fields */);
Implementations
Source§impl<const V: i8> NonValueI8<V>
impl<const V: i8> NonValueI8<V>
Sourcepub const VALID_VALUES: i8 = 127i8
pub const VALID_VALUES: i8 = 127i8
Returns the number of valid values.
Sourcepub const INVALID_VALUES: i8 = 1i8
pub const INVALID_VALUES: i8 = 1i8
Returns the number of invalid values.
Sourcepub const fn new(value: i8) -> Option<Self> ⓘ
pub const fn new(value: i8) -> Option<Self> ⓘ
Returns a NonValueI8
with the given value
, if it is not equal to V
.
Sourcepub const fn new_lossy(value: i8) -> Self
pub const fn new_lossy(value: i8) -> 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: i8) -> Self
pub const unsafe fn new_unchecked(value: i8) -> Self
Sourcepub const fn checked_add(&self, other: i8) -> NumResult<Self>
pub const fn checked_add(&self, other: i8) -> NumResult<Self>
Sourcepub const fn checked_sub(&self, other: i8) -> NumResult<Self>
pub const fn checked_sub(&self, other: i8) -> NumResult<Self>
Sourcepub const fn strict_add(&self, other: i8) -> Self
pub const fn strict_add(&self, other: i8) -> 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: i8) -> Self
pub const fn strict_sub(&self, other: i8) -> 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: i8) -> Self
pub const fn saturating_add(&self, other: i8) -> 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: i8) -> Self
pub const fn saturating_sub(&self, other: i8) -> 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: i8) -> Self
pub const fn wrapping_add(&self, other: i8) -> 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: i8) -> Self
pub const fn wrapping_sub(&self, other: i8) -> 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 ConstDefault for NonExtremeI8
impl ConstDefault for NonExtremeI8
Source§impl Default for NonExtremeI8
impl Default for NonExtremeI8
Source§impl<const V: i8> Binary for NonValueI8<V>
impl<const V: i8> Binary for NonValueI8<V>
Source§impl<const V: i8> BitSized<{$IP::BYTE_SIZE * 8}> for NonValueI8<V>
impl<const V: i8> BitSized<{$IP::BYTE_SIZE * 8}> for NonValueI8<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: i8> CheckedBitPattern for NonValueI8<V>
impl<const V: i8> CheckedBitPattern for NonValueI8<V>
Source§type Bits = i8
type Bits = i8
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: i8> Clone for NonValueI8<V>
impl<const V: i8> Clone for NonValueI8<V>
Source§fn clone(&self) -> NonValueI8<V>
fn clone(&self) -> NonValueI8<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more