Skip to main content

BoundedInt16

Struct BoundedInt16 

Source
pub struct BoundedInt16<const MIN: i16, const MAX: i16> { /* 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: i16, const MAX: i16> BoundedInt16<MIN, MAX>

Source

pub const MAX: i16 = MAX

Upper bound.

Source

pub const MAX_PACKED: Self

Upper bound, represented as the bounded type.

Source

pub const MIN: i16 = MIN

Lower bound.

Source

pub const MIN_PACKED: Self

Lower bound, represented as the bounded type.

Source

pub const fn min(&self) -> i16

Returns Self::MIN.

Source

pub const fn max(&self) -> i16

Returns Self::MAX.

Source

pub fn new<N: Into<i16> + PartialOrd<i16> + 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<i16>>(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<i16> + PartialOrd<i16> + 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) -> i16

Returns the underlying value.

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

Source

pub const fn get_const(&self) -> i16

const-compatible Self::get.

Source

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

Check if abstract value is within bounds.

Source

pub fn clamp(n: i16) -> i16

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

Source

pub fn checked_add<Rhs: Into<i16>>(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<i16>>(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<i16>>(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<i16>>(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<i16>>(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<i16>>(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<i16>>(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<i16>>(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: i16, const MAX: i16> Clone for BoundedInt16<MIN, MAX>

Source§

fn clone(&self) -> BoundedInt16<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: i16, const MAX: i16> Copy for BoundedInt16<MIN, MAX>

Source§

impl<const MIN: i16, const MAX: i16> Debug for BoundedInt16<MIN, MAX>

Source§

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

Example of the string representation:

5 ∈ [1, 10]
Source§

impl<const MIN: i16, const MAX: i16> Display for BoundedInt16<MIN, MAX>

Source§

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

Uses the formatter of the inner_num_repr.

Source§

impl<const MIN: i16, const MAX: i16> Eq for BoundedInt16<MIN, MAX>

Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<const MIN: i16, const MAX: i16> Hash for BoundedInt16<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: i16, const MAX: i16> Into<i16> for BoundedInt16<MIN, MAX>

Source§

fn into(self) -> i16

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

impl<const MIN: i16, const MAX: i16> Ord for BoundedInt16<MIN, MAX>

Source§

fn cmp(&self, other: &BoundedInt16<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: i16, const MAX: i16> PartialEq for BoundedInt16<MIN, MAX>

Source§

fn eq(&self, other: &BoundedInt16<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: i16, const MAX: i16> PartialEq<i16> for BoundedInt16<MIN, MAX>

Source§

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

Equality operator ==. Read more
Source§

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

Inequality operator !=. Read more
Source§

impl<const MIN: i16, const MAX: i16> PartialOrd for BoundedInt16<MIN, MAX>

Source§

fn partial_cmp(&self, other: &BoundedInt16<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: i16, const MAX: i16> PartialOrd<i16> for BoundedInt16<MIN, MAX>

Source§

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

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

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

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

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

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

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

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

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

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

impl<const MIN: i16, const MAX: i16> StructuralPartialEq for BoundedInt16<MIN, MAX>

Source§

impl<const MIN: i16, const MAX: i16> TryFrom<i16> for BoundedInt16<MIN, MAX>

Source§

type Error = Error

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

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

Performs the conversion.

Auto Trait Implementations§

§

impl<const MIN: i16, const MAX: i16> Freeze for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> RefUnwindSafe for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> Send for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> Sync for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> Unpin for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> UnsafeUnpin for BoundedInt16<MIN, MAX>

§

impl<const MIN: i16, const MAX: i16> UnwindSafe for BoundedInt16<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.