Struct deranged::RangedI16

source ·
pub struct RangedI16<const MIN: i16, const MAX: i16>(/* private fields */);
Expand description

An i16 that is known to be in the range MIN..=MAX.

Implementations§

source§

impl RangedI16<0, 0>

source

pub const fn exact<const VALUE: i16>() -> RangedI16<VALUE, VALUE>

source§

impl<const MIN: i16, const MAX: i16> RangedI16<MIN, MAX>

source

pub const MIN: Self = _

The smallest value that can be represented by this type.

source

pub const MAX: Self = _

The largest value that can be represented by this type.

source

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

Creates a ranged integer without checking the value.

§Safety

The value must be within the range MIN..=MAX.

source

pub const fn get(self) -> i16

Returns the value as a primitive type.

source

pub const fn new(value: i16) -> Option<Self>

Creates a ranged integer if the given value is in the range MIN..=MAX.

source

pub const fn new_static<const VALUE: i16>() -> Self

Creates a ranged integer with a statically known value. Fails to compile if the value is not in range.

source

pub const fn new_saturating(value: i16) -> Self

Creates a ranged integer with the given value, saturating if it is out of range.

source

pub const fn expand<const NEW_MIN: i16, const NEW_MAX: i16>( self, ) -> RangedI16<NEW_MIN, NEW_MAX>

Expand the range that the value may be in. Fails to compile if the new range is not a superset of the current range.

source

pub const fn narrow<const NEW_MIN: i16, const NEW_MAX: i16>( self, ) -> Option<RangedI16<NEW_MIN, NEW_MAX>>

Attempt to narrow the range that the value may be in. Returns None if the value is outside the new range. Fails to compile if the new range is not a subset of the current range.

source

pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>

Converts a string slice in a given base to an integer.

The string is expected to be an optional + or - sign followed by digits. Leading and trailing whitespace represent an error. Digits are a subset of these characters, depending on radix:

  • 0-9
  • a-z
  • A-Z
§Panics

Panics if radix is not in the range 2..=36.

§Examples

Basic usage:

assert_eq!(RangedI16::<5, 10>::from_str_radix("A", 16), Ok(RangedI16::new_static::<10>()));
source

pub const fn checked_add(self, rhs: i16) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_add(self, rhs: i16) -> Self

Unchecked integer addition. Computes self + rhs, assuming that the result is in range.

§Safety

The result of self + rhs must be in the range MIN..=MAX.

source

pub const fn checked_sub(self, rhs: i16) -> Option<Self>

Checked integer addition. Computes self - rhs, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_sub(self, rhs: i16) -> Self

Unchecked integer subtraction. Computes self - rhs, assuming that the result is in range.

§Safety

The result of self - rhs must be in the range MIN..=MAX.

source

pub const fn checked_mul(self, rhs: i16) -> Option<Self>

Checked integer addition. Computes self * rhs, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_mul(self, rhs: i16) -> Self

Unchecked integer multiplication. Computes self * rhs, assuming that the result is in range.

§Safety

The result of self * rhs must be in the range MIN..=MAX.

source

pub const fn checked_div(self, rhs: i16) -> Option<Self>

Checked integer addition. Computes self / rhs, returning None if rhs == 0 or if the resulting value is out of range.

source

pub const unsafe fn unchecked_div(self, rhs: i16) -> Self

Unchecked integer division. Computes self / rhs, assuming that rhs != 0 and that the result is in range.

§Safety

self must not be zero and the result of self / rhs must be in the range MIN..=MAX.

source

pub const fn checked_div_euclid(self, rhs: i16) -> Option<Self>

Checked Euclidean division. Computes self.div_euclid(rhs), returning None if rhs == 0 or if the resulting value is out of range.

source

pub const unsafe fn unchecked_div_euclid(self, rhs: i16) -> Self

Unchecked Euclidean division. Computes self.div_euclid(rhs), assuming that rhs != 0 and that the result is in range.

§Safety

self must not be zero and the result of self.div_euclid(rhs) must be in the range MIN..=MAX.

source

pub const fn checked_rem(self, rhs: i16) -> Option<Self>

Checked integer remainder. Computes self % rhs, returning None if rhs == 0 or if the resulting value is out of range.

source

pub const unsafe fn unchecked_rem(self, rhs: i16) -> Self

Unchecked remainder. Computes self % rhs, assuming that rhs != 0 and that the result is in range.

§Safety

self must not be zero and the result of self % rhs must be in the range MIN..=MAX.

source

pub const fn checked_rem_euclid(self, rhs: i16) -> Option<Self>

Checked Euclidean remainder. Computes self.rem_euclid(rhs), returning None if rhs == 0 or if the resulting value is out of range.

source

pub const unsafe fn unchecked_rem_euclid(self, rhs: i16) -> Self

Unchecked Euclidean remainder. Computes self.rem_euclid(rhs), assuming that rhs != 0 and that the result is in range.

§Safety

self must not be zero and the result of self.rem_euclid(rhs) must be in the range MIN..=MAX.

source

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

Checked negation. Computes -self, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_neg(self) -> Self

Unchecked negation. Computes -self, assuming that -self is in range.

§Safety

The result of -self must be in the range MIN..=MAX.

source

pub const fn neg(self) -> Self

Negation. Computes self.neg(), failing to compile if the result is not guaranteed to be in range.

source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self

Unchecked shift left. Computes self << rhs, assuming that the result is in range.

§Safety

The result of self << rhs must be in the range MIN..=MAX.

source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self

Unchecked shift right. Computes self >> rhs, assuming that the result is in range.

§Safety

The result of self >> rhs must be in the range MIN..=MAX.

source

pub const fn checked_abs(self) -> Option<Self>

Checked absolute value. Computes self.abs(), returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_abs(self) -> Self

Unchecked absolute value. Computes self.abs(), assuming that the result is in range.

§Safety

The result of self.abs() must be in the range MIN..=MAX.

source

pub const fn abs(self) -> Self

Absolute value. Computes self.abs(), failing to compile if the result is not guaranteed to be in range.

source

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

Checked exponentiation. Computes self.pow(exp), returning None if the resulting value is out of range.

source

pub const unsafe fn unchecked_pow(self, exp: u32) -> Self

Unchecked exponentiation. Computes self.pow(exp), assuming that the result is in range.

§Safety

The result of self.pow(exp) must be in the range MIN..=MAX.

source

pub const fn saturating_add(self, rhs: i16) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds.

source

pub const fn saturating_sub(self, rhs: i16) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds.

source

pub const fn saturating_neg(self) -> Self

Saturating integer negation. Computes self - rhs, saturating at the numeric bounds.

source

pub const fn saturating_abs(self) -> Self

Saturating absolute value. Computes self.abs(), saturating at the numeric bounds.

source

pub const fn saturating_mul(self, rhs: i16) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds.

source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds.

source

pub const fn wrapping_add(self, rhs: i16) -> Self

Wrapping integer addition. Computes self + rhs, wrapping around the numeric bounds.

source

pub const fn wrapping_sub(self, rhs: i16) -> Self

Wrapping integer subtraction. Computes self - rhs, wrapping around the numeric bounds.

Trait Implementations§

source§

impl<const MIN: i16, const MAX: i16> AsRef<i16> for RangedI16<MIN, MAX>

source§

fn as_ref(&self) -> &i16

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<const MIN: i16, const MAX: i16> Binary for RangedI16<MIN, MAX>

source§

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

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

impl<const MIN: i16, const MAX: i16> Borrow<i16> for RangedI16<MIN, MAX>

source§

fn borrow(&self) -> &i16

Immutably borrows from an owned value. Read more
source§

impl<const MIN: i16, const MAX: i16> Clone for RangedI16<MIN, MAX>

source§

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

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 MIN: i16, const MAX: i16> Debug for RangedI16<MIN, MAX>

source§

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

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

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

source§

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

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

impl<const MIN: i16, const MAX: i16> From<RangedI16<MIN, MAX>> for OptionRangedI16<MIN, MAX>

source§

fn from(value: RangedI16<MIN, MAX>) -> Self

Converts to this type from the input type.
source§

impl<const MIN: i16, const MAX: i16> From<RangedI16<MIN, MAX>> for i16

source§

fn from(value: RangedI16<MIN, MAX>) -> Self

Converts to this type from the input type.
source§

impl<const MIN: i16, const MAX: i16> FromStr for RangedI16<MIN, MAX>

§

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 MIN: i16, const MAX: i16> Hash for RangedI16<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> LowerExp for RangedI16<MIN, MAX>

source§

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

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

impl<const MIN: i16, const MAX: i16> LowerHex for RangedI16<MIN, MAX>

source§

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

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

impl<const MIN: i16, const MAX: i16> Octal for RangedI16<MIN, MAX>

source§

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

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

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

source§

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

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

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

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

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

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

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

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

impl<const MIN_A: i16, const MAX_A: i16, const MIN_B: i16, const MAX_B: i16> PartialEq<RangedI16<MIN_B, MAX_B>> for RangedI16<MIN_A, MAX_A>

source§

fn eq(&self, other: &RangedI16<MIN_B, MAX_B>) -> 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 MIN_A: i16, const MAX_A: i16, const MIN_B: i16, const MAX_B: i16> PartialOrd<RangedI16<MIN_B, MAX_B>> for RangedI16<MIN_A, MAX_A>

source§

fn partial_cmp(&self, other: &RangedI16<MIN_B, MAX_B>) -> 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 MIN: i16, const MAX: i16> SmartDisplay for RangedI16<MIN, MAX>

§

type Metadata = <i16 as SmartDisplay>::Metadata

User-provided metadata type.
source§

fn metadata(&self, f: FormatterOptions) -> Metadata<'_, Self>

Compute any information needed to format the value. This must, at a minimum, determine the width of the value before any padding is added by the formatter. Read more
source§

fn fmt_with_metadata( &self, f: &mut Formatter<'_>, metadata: Metadata<'_, Self>, ) -> Result

Format the value using the given formatter and metadata. The formatted output should have the width indicated by the metadata. This is before any padding is added by the formatter. Read more
source§

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

Format the value using the given formatter. This is the same as Display::fmt. Read more
source§

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

§

type Error = TryFromIntError

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

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

Performs the conversion.
source§

impl<const MIN: i16, const MAX: i16> UpperExp for RangedI16<MIN, MAX>

source§

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

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

impl<const MIN: i16, const MAX: i16> UpperHex for RangedI16<MIN, MAX>

source§

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

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

impl<const MIN: i16, const MAX: i16> Copy for RangedI16<MIN, MAX>

source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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§

default 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>,

§

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>,

§

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.