Struct devela::num::NonRangeIsize

source ·
#[repr(C)]
pub struct NonRangeIsize<const RMIN: isize, const RMAX: isize>(/* private fields */);
Available on crate feature 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>

source

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.

source

pub const unsafe fn new_unchecked(value: isize) -> Self

Available on crate feature unsafe_num only.

Returns a NonRangeIsize if the given value is not between RMIN and RMAX.

Panics

Panics in debug if the given value is between RMIN and RMAX, inclusive, or if RMIN > RMAX.

Safety

The given value must never be between RMIN and RMAX, inclusive.

source

pub const fn get(&self) -> isize

Returns the value as a primitive type.

source

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.

source

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> Binary for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<const RMIN: isize, const RMAX: isize> BitSize<8> for NonRangeIsize<RMIN, RMAX>

Available on crate feature mem only.
source§

const BIT_SIZE: usize = _

The bit size of this type (only the relevant data part, without padding). Read more
source§

const MIN_BYTE_SIZE: usize = _

The rounded up byte size for this type. Read more
source§

fn bit_size(&self) -> usize

Returns the bit size of this type (only the relevant data part, without padding). Read more
source§

fn min_byte_size(&self) -> usize

Returns the rounded up byte size for this type. Read more
source§

impl<const RMIN: isize, const RMAX: isize> Clone for NonRangeIsize<RMIN, RMAX>

source§

fn clone(&self) -> NonRangeIsize<RMIN, RMAX>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const RMIN: isize, const RMAX: isize> Debug for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const RMIN: isize, const RMAX: isize> Display for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const RMIN: isize, const RMAX: isize> From<NonRangeIsize<RMIN, RMAX>> for isize

source§

fn from(value: NonRangeIsize<RMIN, RMAX>) -> isize

Converts to this type from the input type.
source§

impl<const RMIN: isize, const RMAX: isize> FromStr for NonRangeIsize<RMIN, RMAX>

§

type Err = ParseIntError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<const RMIN: isize, const RMAX: isize> Hash for NonRangeIsize<RMIN, RMAX>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<const RMIN: isize, const RMAX: isize> LowerHex for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<const RMIN: isize, const RMAX: isize> Num for NonRangeIsize<RMIN, RMAX>

§

type Inner = isize

The internal representation of this numeric type.
§

type OpOut = NonRangeIsize<RMIN, RMAX>

The output type for operations.
§

type OpRhs = NonRangeIsize<RMIN, RMAX>

The right hand side type for operations.
source§

fn num_into(self) -> Self::Inner

Returns the inner self representation.
source§

fn num_from(from: Self::Inner) -> Result<Self>

Returns Self if given a valid value.
source§

fn num_from_ref(from: &Self::Inner) -> Result<Self>

Returns Self if given a valid &value.
source§

fn num_set(&mut self, value: Self::Inner) -> Result<()>

Sets self to the given valid value.
source§

fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>

Sets self to the given valid &value.
source§

fn num_is_zero(&self) -> Result<bool>

Returns true if self is zero.
source§

fn num_is_one(&self) -> Result<bool>

Returns true if self is one.
source§

fn num_get_zero() -> Result<Self>

Returns the number zero.
source§

fn num_get_one() -> Result<Self>

Returns the number one.
source§

fn num_set_zero(&mut self) -> Result<()>

Sets self to 0.
source§

fn num_set_one(&mut self) -> Result<()>

Sets the number to one.
source§

fn num_add(self, other: Self) -> Result<Self::OpOut>

Computes self + other.
source§

fn num_add_ref(self, other: &Self) -> Result<Self::OpOut>

Computes self + &other.
source§

fn num_ref_add(&self, other: Self) -> Result<Self::OpOut>

Computes &self + other.
source§

fn num_ref_add_ref(&self, other: &Self) -> Result<Self::OpOut>

Computes &self + &other.
source§

fn num_mul(self, other: Self) -> Result<Self::OpOut>

Computes self * other.
source§

fn num_mul_ref(self, other: &Self) -> Result<Self::OpOut>

Computes self * &other.
source§

fn num_ref_mul(&self, other: Self) -> Result<Self::OpOut>

Computes &self * other.
source§

fn num_ref_mul_ref(&self, other: &Self) -> Result<Self::OpOut>

Computes &self * &other.
source§

fn num_sub(self, other: Self) -> Result<Self::OpOut>

Computes self - other.
source§

fn num_sub_ref(self, other: &Self) -> Result<Self::OpOut>

Computes self - &other.
source§

fn num_ref_sub(&self, other: Self) -> Result<Self::OpOut>

Computes &self - other.
source§

fn num_ref_sub_ref(&self, other: &Self) -> Result<Self::OpOut>

Computes &self - &other.
source§

fn num_div(self, other: Self) -> Result<Self::OpOut>

Computes self / other.
source§

fn num_div_ref(self, other: &Self) -> Result<Self::OpOut>

Computes self / &other.
source§

fn num_ref_div(&self, other: Self) -> Result<Self::OpOut>

Computes &self / other.
source§

fn num_ref_div_ref(&self, other: &Self) -> Result<Self::OpOut>

Computes &self / &other.
source§

fn num_rem(self, other: Self) -> Result<Self::OpOut>

Computes self % other.
source§

fn num_rem_ref(self, other: &Self) -> Result<Self::OpOut>

Computes self % &other.
source§

fn num_ref_rem(&self, other: Self) -> Result<Self::OpOut>

Computes &self % other.
source§

fn num_ref_rem_ref(&self, other: &Self) -> Result<Self::OpOut>

Computes &self % &other.
source§

fn num_neg(self) -> Result<Self::OpOut>

Computes - self.
source§

fn num_ref_neg(&self) -> Result<Self::OpOut>

Computes - &self.
source§

fn num_abs(self) -> Result<Self::OpOut>

Computes the absolute value of self.
source§

fn num_ref_abs(&self) -> Result<Self::OpOut>

Computes the absolute value of &self.
source§

impl<const RMIN: isize, const RMAX: isize> Octal for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<const RMIN: isize, const RMAX: isize> Ord for NonRangeIsize<RMIN, RMAX>

source§

fn cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<const RMIN: isize, const RMAX: isize> PartialEq for NonRangeIsize<RMIN, RMAX>

source§

fn eq(&self, other: &NonRangeIsize<RMIN, RMAX>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const RMIN: isize, const RMAX: isize> PartialOrd for NonRangeIsize<RMIN, RMAX>

source§

fn partial_cmp(&self, other: &NonRangeIsize<RMIN, RMAX>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const RMIN: isize, const RMAX: isize> TryFrom<isize> for NonRangeIsize<RMIN, RMAX>

§

type Error = TryFromIntError

The type returned in the event of a conversion error.
source§

fn try_from(value: isize) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<const RMIN: isize, const RMAX: isize> UpperHex for NonRangeIsize<RMIN, RMAX>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<const RMIN: isize, const RMAX: isize> Copy for NonRangeIsize<RMIN, RMAX>

source§

impl<const RMIN: isize, const RMAX: isize> Eq for NonRangeIsize<RMIN, RMAX>

source§

impl<const RMIN: isize, const RMAX: isize> IntBufAble for NonRangeIsize<RMIN, RMAX>

Available on crate features unsafe_text and text only.
source§

impl<const RMIN: isize, const RMAX: isize> StructuralEq for NonRangeIsize<RMIN, RMAX>

source§

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

source§

fn also_mut<F: FnOnce(&mut Self)>(self, f: F) -> Self

Available on crate feature result only.
Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
source§

fn also_ref<F: FnOnce(&Self)>(self, f: F) -> Self

Available on crate feature result only.
Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyExt for Twhere T: Any,

source§

fn type_of(&self) -> TypeId

Available on crate feature any only.
Returns the TypeId of self. Read more
source§

fn type_name(&self) -> &'static str

Available on crate feature any only.
Returns the type name of self. Read more
source§

fn type_is<T: 'static>(&self) -> bool

Available on crate feature any only.
Returns true if Self is of type T. Read more
source§

fn as_any_ref(&self) -> &dyn Anywhere Self: Sized,

Available on crate feature any only.
Upcasts &self as &dyn Any. Read more
source§

fn as_any_mut(&mut self) -> &mut dyn Anywhere Self: Sized,

Available on crate feature any only.
Upcasts &mut self as &mut dyn Any. Read more
source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>where Self: Sized,

Available on crate feature any only.
Upcasts Box<self> as Box<dyn Any>. Read more
source§

impl<T, Res> Apply<Res> for Twhere T: ?Sized,

source§

fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere Self: Sized,

Available on crate feature result only.
Apply a function which takes the parameter by value.
source§

fn apply_ref<F: FnOnce(&Self) -> Res>(&self, f: F) -> Res

Available on crate feature result only.
Apply a function which takes the parameter by shared reference.
source§

fn apply_mut<F: FnOnce(&mut Self) -> Res>(&mut self, f: F) -> Res

Available on crate feature result only.
Apply a function which takes the parameter by exclusive reference.
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Mem for Twhere T: ?Sized,

source§

const NEEDS_DROP: bool = _

Available on crate feature mem only.
Whether dropping values of this type matters.
source§

fn mem_needs_drop(&self) -> bool

Available on crate feature mem only.
Returns true if dropping values of this type matters.
source§

fn mem_drop(self)where Self: Sized,

Available on crate feature mem only.
Drops self by running its destructor.
source§

fn mem_forget(self)where Self: Sized,

Available on crate feature mem only.
Forgets about self without running its destructor.
source§

fn mem_replace(&mut self, other: Self) -> Selfwhere Self: Sized,

Available on crate feature mem only.
Replaces self with other, returning the previous value of self.
source§

fn mem_take(&mut self) -> Selfwhere Self: Default,

Available on crate feature mem only.
Replaces self with its default value, returning the previous value of self.
source§

fn mem_swap(&mut self, other: &mut Self)where Self: Sized,

Available on crate feature mem only.
Swaps the value of self and other without deinitializing either one.
source§

fn mem_as_bytes(&self) -> &[u8] where Self: Sync + Unpin,

Available on crate features mem and unsafe_mem only.
View a Sync + Unpin self as &[u8]. Read more
source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8] where Self: Sync + Unpin,

Available on crate features mem and unsafe_mem only.
View a Sync + Unpin self as &mut [u8].
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> Size for T

source§

const BYTE_ALIGN: usize = _

Available on crate feature mem only.
The alignment of this type in bytes.
source§

const BYTE_SIZE: usize = _

Available on crate feature mem only.
The size of this type in bytes.
source§

const PTR_SIZE: usize = 4usize

Available on crate feature mem only.
The size of a pointer in bytes, for the current platform.
source§

fn byte_align(&self) -> usize

Available on crate feature mem only.
Returns the alignment of this type in bytes.
source§

fn byte_size(&self) -> usize

Available on crate feature mem only.
Returns the size of this type in bytes. Read more
source§

fn ptr_ratio(&self) -> (usize, usize)

Available on crate feature mem only.
Returns the size ratio between PTR_SIZE and BYTE_SIZE. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.