Skip to main content

BoundedIsize

Struct BoundedIsize 

Source
pub struct BoundedIsize<const MIN: isize, const MAX: isize> { /* private fields */ }
Expand description

Bounded type (inclusive) that holds a value that is MIN <= value <= MAX

Has the same representation as the primitive type.

§Safety

Creating an instance with MIN > MAX is undefined behavior.

Implementations§

Source§

impl<const MIN: isize, const MAX: isize> BoundedIsize<MIN, MAX>

Source

pub const MAX: isize = MAX

Upper bound.

Source

pub const MAX_PACKED: Self

Upper bound, represented as the bounded type.

Source

pub const MIN: isize = MIN

Lower bound.

Source

pub const MIN_PACKED: Self

Lower bound, represented as the bounded type.

Source

pub const fn min(&self) -> isize

Returns Self::MIN.

Source

pub const fn max(&self) -> isize

Returns Self::MAX.

Source

pub fn new<N: Into<isize> + PartialOrd<isize> + Ord>( value: N, ) -> Result<Self, Error>

Create a new value of the type.

Returns the error if the provided value was outside of the defined bounds.

Source

pub unsafe fn new_unchecked<N: Into<isize>>(value: N) -> Self

Create a new value of the type without any checks.

§Safety

User is responsible for providing the value that is already between the defined bounds. Creating a value outside of the defined bounds is undefined behavior.

Source

pub fn new_clamped<N: Into<isize> + PartialOrd<isize> + Ord>(value: N) -> Self

Create a new value of the type.

If value is within range, returns a new instance; otherwise, clamps it to the upper or lower bound.

Source

pub fn get(self) -> isize

Returns the underlying value.

This value is guaranteed to be between Self::MIN and Self::MAX.

Source

pub const fn get_const(&self) -> isize

const-compatible Self::get.

Source

pub fn is_in_bounds(n: &isize) -> bool

Check if abstract value is within bounds.

Source

pub fn clamp(n: isize) -> isize

Clamp the provided n between the Self::MIN and Self::MAX.

Source

pub fn checked_add<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if either bound overflow or integer overflow occurred.

Source

pub unsafe fn unchecked_add<Rhs: Into<isize>>(self, rhs: Rhs) -> Self

Unchecked integer addition. Computes self + rhs, assuming overflow cannot occur.

§Safety

This results in undefined behavior if the result overflows the primitive type’s bounds or the [MIN, MAX] bounds of this type.

Source

pub fn checked_sub<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if either bound overflow or integer overflow occurred.

Source

pub unsafe fn unchecked_sub<Rhs: Into<isize>>(self, rhs: Rhs) -> Self

Unchecked integer subtraction. Computes self - rhs, assuming overflow cannot occur.

§Safety

This results in undefined behavior if the result overflows the primitive type’s bounds or the [MIN, MAX] bounds of this type.

Source

pub fn checked_mul<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if either bound overflow or integer overflow occurred.

Source

pub unsafe fn unchecked_mul<Rhs: Into<isize>>(self, rhs: Rhs) -> Self

Unchecked integer multiplication. Computes self * rhs, assuming overflow cannot occur.

§Safety

This results in undefined behavior if the result overflows the primitive type’s bounds or the [MIN, MAX] bounds of this type.

Source

pub fn checked_div<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if either bound overflow or integer overflow occurred.

Source

pub fn checked_rem<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>

Checked integer remainder. Computes self % rhs, returning None if either bound overflow or integer overflow occurred.

Source

pub fn checked_neg(self) -> Option<Self>

Checked negation. Computes -self, returning None if bound overflow or self == inner_num_repr::MIN occurred.

Source

pub fn checked_pow(self, exp: u32) -> Option<Self>

Checked integer exponentiation. Computes self.pow(), returning None if bound overflow or self == inner_num_repr::MIN occurred.

Trait Implementations§

Source§

impl<const MIN: isize, const MAX: isize> Clone for BoundedIsize<MIN, MAX>

Source§

fn clone(&self) -> BoundedIsize<MIN, MAX>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const MIN: isize, const MAX: isize> Copy for BoundedIsize<MIN, MAX>

Source§

impl<const MIN: isize, const MAX: isize> Debug for BoundedIsize<MIN, MAX>

Source§

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

Example of the string representation:

5 ∈ [1, 10]
Source§

impl<const MIN: isize, const MAX: isize> Display for BoundedIsize<MIN, MAX>

Source§

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

Uses the formatter of the inner_num_repr.

Source§

impl<const MIN: isize, const MAX: isize> Eq for BoundedIsize<MIN, MAX>

Source§

impl From<BoundedIsize<{ i8::MIN as _ }, { i8::MAX as _ }>> for i8

Source§

fn from(value: BoundedIsize<-128, 127>) -> Self

Converts to this type from the input type.
Source§

impl From<BoundedIsize<{ i16::MIN as _ }, { i16::MAX as _ }>> for i16

Source§

fn from(value: BoundedIsize<-32768, 32767>) -> Self

Converts to this type from the input type.
Source§

impl From<BoundedIsize<{ i32::MIN as _ }, { i32::MAX as _ }>> for i32

Source§

fn from(value: BoundedIsize<-2147483648, 2147483647>) -> Self

Converts to this type from the input type.
Source§

impl From<BoundedIsize<{ u8::MIN as _ }, { u8::MAX as _ }>> for u8

Source§

fn from(value: BoundedIsize<0, 255>) -> Self

Converts to this type from the input type.
Source§

impl From<BoundedIsize<{ u16::MIN as _ }, { u16::MAX as _ }>> for u16

Source§

fn from(value: BoundedIsize<0, 65535>) -> Self

Converts to this type from the input type.
Source§

impl<const MIN: isize, const MAX: isize> Hash for BoundedIsize<MIN, MAX>

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 MIN: isize, const MAX: isize> Into<isize> for BoundedIsize<MIN, MAX>

Source§

fn into(self) -> isize

Converts this type into the (usually inferred) input type.
Source§

impl<const MIN: isize, const MAX: isize> Ord for BoundedIsize<MIN, MAX>

Source§

fn cmp(&self, other: &BoundedIsize<MIN, MAX>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl<const MIN: isize, const MAX: isize> PartialEq for BoundedIsize<MIN, MAX>

Source§

fn eq(&self, other: &BoundedIsize<MIN, MAX>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const MIN: isize, const MAX: isize> PartialEq<isize> for BoundedIsize<MIN, MAX>

Source§

fn eq(&self, other: &isize) -> bool

Equality operator ==. Read more
Source§

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

Inequality operator !=. Read more
Source§

impl<const MIN: isize, const MAX: isize> PartialOrd for BoundedIsize<MIN, MAX>

Source§

fn partial_cmp(&self, other: &BoundedIsize<MIN, MAX>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const MIN: isize, const MAX: isize> PartialOrd<isize> for BoundedIsize<MIN, MAX>

Source§

fn partial_cmp(&self, other: &isize) -> Option<Ordering>

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

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

Tests less than (for self and other) and is used by the < operator. Read more
Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const MIN: isize, const MAX: isize> StructuralPartialEq for BoundedIsize<MIN, MAX>

Source§

impl<const MIN: isize, const MAX: isize> TryFrom<isize> for BoundedIsize<MIN, MAX>

Source§

type Error = Error

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

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

Performs the conversion.

Auto Trait Implementations§

§

impl<const MIN: isize, const MAX: isize> Freeze for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> RefUnwindSafe for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> Send for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> Sync for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> Unpin for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> UnsafeUnpin for BoundedIsize<MIN, MAX>

§

impl<const MIN: isize, const MAX: isize> UnwindSafe for BoundedIsize<MIN, MAX>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.