deranged

Struct RangedI64

Source
pub struct RangedI64<const MIN: i64, const MAX: i64>(/* private fields */);
Expand description

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

Implementations§

Source§

impl RangedI64<0, 0>

Source

pub const fn exact<const VALUE: i64>() -> RangedI64<VALUE, VALUE>

Source§

impl<const MIN: i64, const MAX: i64> RangedI64<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: i64) -> 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) -> i64

Returns the value as a primitive type.

Source

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

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

Source

pub const fn new_static<const VALUE: i64>() -> 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: i64) -> Self

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

Source

pub const fn expand<const NEW_MIN: i64, const NEW_MAX: i64>( self, ) -> RangedI64<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: i64, const NEW_MAX: i64>( self, ) -> Option<RangedI64<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!(RangedI64::<5, 10>::from_str_radix("A", 16), Ok(RangedI64::new_static::<10>()));
Source

pub const fn checked_add(self, rhs: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> 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: i64) -> Self

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

Source

pub const fn saturating_sub(self, rhs: i64) -> 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: i64) -> 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: i64) -> Self

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

Source

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

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

Trait Implementations§

Source§

impl<const MIN: i64, const MAX: i64> Arbitrary for RangedI64<MIN, MAX>

Source§

fn arbitrary(g: &mut Gen) -> Self

Return an arbitrary value. Read more
Source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself. Read more
Source§

impl<const MIN: i64, const MAX: i64> AsRef<i64> for RangedI64<MIN, MAX>

Source§

fn as_ref(&self) -> &i64

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

impl<const MIN: i64, const MAX: i64> Binary for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> Borrow<i64> for RangedI64<MIN, MAX>

Source§

fn borrow(&self) -> &i64

Immutably borrows from an owned value. Read more
Source§

impl<const MIN: i64, const MAX: i64> Clone for RangedI64<MIN, MAX>

Source§

fn clone(&self) -> RangedI64<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: i64, const MAX: i64> Debug for RangedI64<MIN, MAX>

Source§

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

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

impl<'de, const MIN: i64, const MAX: i64> Deserialize<'de> for RangedI64<MIN, MAX>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const MIN: i64, const MAX: i64> Display for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> Distribution<RangedI64<MIN, MAX>> for Standard

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> RangedI64<MIN, MAX>

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
Source§

impl<const MIN: i64, const MAX: i64> From<RangedI64<MIN, MAX>> for OptionRangedI64<MIN, MAX>

Source§

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

Converts to this type from the input type.
Source§

impl<const MIN: i64, const MAX: i64> From<RangedI64<MIN, MAX>> for i64

Source§

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

Converts to this type from the input type.
Source§

impl<const MIN: i64, const MAX: i64> FromStr for RangedI64<MIN, MAX>

Source§

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

Source§

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

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

impl<const MIN: i64, const MAX: i64> LowerHex for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> Octal for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> Ord for RangedI64<MIN, MAX>

Source§

fn cmp(&self, other: &RangedI64<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,

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

impl<const MIN_A: i64, const MAX_A: i64, const MIN_B: i64, const MAX_B: i64> PartialEq<RangedI64<MIN_B, MAX_B>> for RangedI64<MIN_A, MAX_A>

Source§

fn eq(&self, other: &RangedI64<MIN_B, MAX_B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const MIN_A: i64, const MAX_A: i64, const MIN_B: i64, const MAX_B: i64> PartialOrd<RangedI64<MIN_B, MAX_B>> for RangedI64<MIN_A, MAX_A>

Source§

fn partial_cmp(&self, other: &RangedI64<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

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

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

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

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

impl<const MIN: i64, const MAX: i64> Serialize for RangedI64<MIN, MAX>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<const MIN: i64, const MAX: i64> SmartDisplay for RangedI64<MIN, MAX>

Source§

type Metadata = <i64 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: i64, const MAX: i64> TryFrom<i64> for RangedI64<MIN, MAX>

Source§

type Error = TryFromIntError

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

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

Performs the conversion.
Source§

impl<const MIN: i64, const MAX: i64> UpperExp for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> UpperHex for RangedI64<MIN, MAX>

Source§

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

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

impl<const MIN: i64, const MAX: i64> Copy for RangedI64<MIN, MAX>

Source§

impl<const MIN: i64, const MAX: i64> Eq for RangedI64<MIN, MAX>

Auto Trait Implementations§

§

impl<const MIN: i64, const MAX: i64> Freeze for RangedI64<MIN, MAX>

§

impl<const MIN: i64, const MAX: i64> RefUnwindSafe for RangedI64<MIN, MAX>

§

impl<const MIN: i64, const MAX: i64> Send for RangedI64<MIN, MAX>

§

impl<const MIN: i64, const MAX: i64> Sync for RangedI64<MIN, MAX>

§

impl<const MIN: i64, const MAX: i64> Unpin for RangedI64<MIN, MAX>

§

impl<const MIN: i64, const MAX: i64> UnwindSafe for RangedI64<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, dst: *mut u8)

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

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,