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>
impl<const MIN: isize, const MAX: isize> BoundedIsize<MIN, MAX>
Sourcepub const MAX_PACKED: Self
pub const MAX_PACKED: Self
Upper bound, represented as the bounded type.
Sourcepub const MIN_PACKED: Self
pub const MIN_PACKED: Self
Lower bound, represented as the bounded type.
Sourcepub fn new<N: Into<isize> + PartialOrd<isize> + Ord>(
value: N,
) -> Result<Self, Error>
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.
Sourcepub unsafe fn new_unchecked<N: Into<isize>>(value: N) -> Self
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.
Sourcepub fn new_clamped<N: Into<isize> + PartialOrd<isize> + Ord>(value: N) -> Self
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.
Sourcepub fn get(self) -> isize
pub fn get(self) -> isize
Returns the underlying value.
This value is guaranteed to be between Self::MIN and Self::MAX.
Sourcepub fn is_in_bounds(n: &isize) -> bool
pub fn is_in_bounds(n: &isize) -> bool
Check if abstract value is within bounds.
Sourcepub fn checked_add<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>
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.
Sourcepub unsafe fn unchecked_add<Rhs: Into<isize>>(self, rhs: Rhs) -> Self
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.
Sourcepub fn checked_sub<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>
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.
Sourcepub unsafe fn unchecked_sub<Rhs: Into<isize>>(self, rhs: Rhs) -> Self
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.
Sourcepub fn checked_mul<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>
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.
Sourcepub unsafe fn unchecked_mul<Rhs: Into<isize>>(self, rhs: Rhs) -> Self
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.
Sourcepub fn checked_div<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>
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.
Sourcepub fn checked_rem<Rhs: Into<isize>>(self, rhs: Rhs) -> Option<Self>
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.
Sourcepub fn checked_neg(self) -> Option<Self>
pub fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self, returning None if bound overflow
or self == inner_num_repr::MIN occurred.
Sourcepub fn checked_pow(self, exp: u32) -> Option<Self>
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>
impl<const MIN: isize, const MAX: isize> Clone for BoundedIsize<MIN, MAX>
Source§fn clone(&self) -> BoundedIsize<MIN, MAX>
fn clone(&self) -> BoundedIsize<MIN, MAX>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more