Struct devela::num::NonRangeIsize
source · #[repr(C)]pub struct NonRangeIsize<const RMIN: isize, const RMAX: isize>(/* private fields */);num only.Expand description
A signed integer that is known to be excluded from some inclusive range.
It has an optimized memory layout, so that
Option<NonRangeIsize> is the same size as NonRangeIsize.
Examples
use devela::num::NonRangeIsize;
assert![NonRangeIsize::<5, 25>::new(5).is_none()];
assert![NonRangeIsize::<5, 25>::new(25).is_none()];
assert![NonRangeIsize::<5, 25>::new(4).unwrap().get() == 4];
assert![NonRangeIsize::<5, 25>::new(26).unwrap().get() == 26];
// Self::INVALID_VALUES + Self::VALID_VALUES == usize::MAX + 1.
assert![NonRangeIsize::<5, 25>::VALID_VALUES == usize::MAX - 21 + 1];
assert![NonRangeIsize::<5, 25>::INVALID_VALUES == 21];Implementations§
source§impl<const RMIN: isize, const RMAX: isize> NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> NonRangeIsize<RMIN, RMAX>
sourcepub const fn new(value: isize) -> Option<Self>
pub const fn new(value: isize) -> Option<Self>
Returns a NonRangeIsize with the given value, only if it’s not between RMIN and RMAX.
Returns None if value is between RMIN and RMAX, inclusive,
or if RMIN > RMAX.
sourcepub const unsafe fn new_unchecked(value: isize) -> Self
Available on crate feature unsafe_num only.
pub const unsafe fn new_unchecked(value: isize) -> Self
unsafe_num only.sourcepub const VALID_VALUES: usize = _
pub const VALID_VALUES: usize = _
Returns the number of valid values outside the range from RMIN to RMAX,
inclusive, as an unsigned integer with equal bit size.
Notice
A range where RMAX == RMIN will result in VALID_VALUES == usize::MAX, as expected.
A range from isize::MIN to isize::MAX will result
in VALID_VALUES == 0, also as expected.
Just be aware that in this case INVALID_VALUES will also be == 0 instead of
usize::MAX + 1.
sourcepub const INVALID_VALUES: usize = _
pub const INVALID_VALUES: usize = _
Returns the number of invalid values in the range from RMIN to RMAX,
inclusive, as an unsigned integer with equal bit size.
Notice
A range where RMAX == RMIN will result in INVALID_VALUES == 1, as expected.
A range from isize::MIN to isize::MAX will result in INVALID_VALUES == 0 instead of usize::MAX + 1.
This is because the maximum number of representable values for a given
bit-size can’t be represented using the same number of bits.
In this case VALID_VALUES will also be == 0.
This doesn’t matter as much because a NonRangeIsize with the
largest range of invalid values can’t ever be constructed.
Remember that INVALID_VALUES + VALID_VALUES == usize::MAX + 1,
which would wrap to 0.
Trait Implementations§
source§impl<const RMIN: isize, const RMAX: isize> BitSize<8> for NonRangeIsize<RMIN, RMAX>
Available on crate feature mem only.
impl<const RMIN: isize, const RMAX: isize> BitSize<8> for NonRangeIsize<RMIN, RMAX>
mem only.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 RMIN: isize, const RMAX: isize> Clone for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Clone for NonRangeIsize<RMIN, RMAX>
source§fn clone(&self) -> NonRangeIsize<RMIN, RMAX>
fn clone(&self) -> NonRangeIsize<RMIN, RMAX>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<const RMIN: isize, const RMAX: isize> From<NonRangeIsize<RMIN, RMAX>> for isize
impl<const RMIN: isize, const RMAX: isize> From<NonRangeIsize<RMIN, RMAX>> for isize
source§fn from(value: NonRangeIsize<RMIN, RMAX>) -> isize
fn from(value: NonRangeIsize<RMIN, RMAX>) -> isize
source§impl<const RMIN: isize, const RMAX: isize> Num for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Num for NonRangeIsize<RMIN, RMAX>
§type Out = NonRangeIsize<RMIN, RMAX>
type Out = NonRangeIsize<RMIN, RMAX>
§type Rhs = NonRangeIsize<RMIN, RMAX>
type Rhs = NonRangeIsize<RMIN, RMAX>
source§fn num_from_ref(from: &Self::Inner) -> Result<Self>
fn num_from_ref(from: &Self::Inner) -> Result<Self>
Self if given a valid &value.source§fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
self to the given valid &value.source§fn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
true if self is zero.source§fn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
true if self is one.source§fn num_get_zero() -> Result<Self>
fn num_get_zero() -> Result<Self>
source§fn num_get_one() -> Result<Self>
fn num_get_one() -> Result<Self>
source§fn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
self to 0.source§fn num_set_one(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
source§fn num_ref_add(&self, other: Self) -> Result<Self::Out>
fn num_ref_add(&self, other: Self) -> Result<Self::Out>
&self + other.source§fn num_ref_mul(&self, other: Self) -> Result<Self::Out>
fn num_ref_mul(&self, other: Self) -> Result<Self::Out>
&self * other.source§fn num_ref_sub(&self, other: Self) -> Result<Self::Out>
fn num_ref_sub(&self, other: Self) -> Result<Self::Out>
&self - other.source§fn num_ref_div(&self, other: Self) -> Result<Self::Out>
fn num_ref_div(&self, other: Self) -> Result<Self::Out>
&self / other.source§fn num_ref_rem(&self, other: Self) -> Result<Self::Out>
fn num_ref_rem(&self, other: Self) -> Result<Self::Out>
&self % other.source§fn num_ref_neg(&self) -> Result<Self::Out>
fn num_ref_neg(&self) -> Result<Self::Out>
- &self.source§fn num_ref_abs(&self) -> Result<Self::Out>
fn num_ref_abs(&self) -> Result<Self::Out>
&self.source§impl<const RMIN: isize, const RMAX: isize> Ord for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Ord for NonRangeIsize<RMIN, RMAX>
source§fn cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Ordering
fn cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<const RMIN: isize, const RMAX: isize> PartialEq for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> PartialEq for NonRangeIsize<RMIN, RMAX>
source§fn eq(&self, other: &NonRangeIsize<RMIN, RMAX>) -> bool
fn eq(&self, other: &NonRangeIsize<RMIN, RMAX>) -> bool
self and other values to be equal, and is used
by ==.source§impl<const RMIN: isize, const RMAX: isize> PartialOrd for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> PartialOrd for NonRangeIsize<RMIN, RMAX>
source§fn partial_cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Option<Ordering>
fn partial_cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl<const RMIN: isize, const RMAX: isize> Copy for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Eq for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> IntBufAble for NonRangeIsize<RMIN, RMAX>
unsafe_text and text only.impl<const RMIN: isize, const RMAX: isize> StructuralEq for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> StructuralPartialEq for NonRangeIsize<RMIN, RMAX>
Auto Trait Implementations§
impl<const RMIN: isize, const RMAX: isize> RefUnwindSafe for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Send for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Sync for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> Unpin for NonRangeIsize<RMIN, RMAX>
impl<const RMIN: isize, const RMAX: isize> UnwindSafe for NonRangeIsize<RMIN, RMAX>
Blanket Implementations§
source§impl<T> Also for T
impl<T> Also for T
source§impl<T> AnyExt for Twhere
T: Any,
impl<T> AnyExt for Twhere
T: Any,
source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
any only.self. Read moresource§fn as_any_ref(&self) -> &dyn Anywhere
Self: Sized,
fn as_any_ref(&self) -> &dyn Anywhere
Self: Sized,
any only.source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
any only.source§impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
source§fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere
Self: Sized,
fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere
Self: Sized,
result 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
§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> Mem for Twhere
T: ?Sized,
impl<T> Mem for Twhere
T: ?Sized,
source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
mem only.source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
mem only.true if dropping values of this type matters.source§fn mem_drop(self)where
Self: Sized,
fn mem_drop(self)where
Self: Sized,
mem only.self by running its destructor.source§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
mem only.self without running its destructor.source§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
mem only.self with other, returning the previous value of self.source§fn mem_take(&mut self) -> Selfwhere
Self: Default,
fn mem_take(&mut self) -> Selfwhere
Self: Default,
mem only.self with its default value, returning the previous value of self.source§fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
mem only.self and other without deinitializing either one.source§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
mem and unsafe_mem only.source§impl<T> Size for T
impl<T> Size for T
source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
mem only.source§const BYTE_SIZE: usize = _
const BYTE_SIZE: usize = _
mem only.source§const PTR_SIZE: usize = 4usize
const PTR_SIZE: usize = 4usize
mem only.source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
mem only.