[]Struct matrix_sdk_base::Int

pub struct Int(_);

An integer limited to the range of integers that can be represented exactly by an f64.

Implementations

impl Int

pub const MIN: Int

The smallest value that can be represented by this integer type.

Examples

Basic usage:

assert_eq!(Int::MIN, Int::try_from(-9_007_199_254_740_991i64).unwrap());

pub const MAX: Int

The largest value that can be represented by this integer type.

Examples

Basic usage:

assert_eq!(Int::MAX, Int::try_from(9_007_199_254_740_991i64).unwrap());

#[must_use]pub fn new(val: i64) -> Option<Int>

Try to create an Int from the provided i64, returning None if it is smaller than MIN_SAFE_INT or larger than MAX_SAFE_INT.

This is the same as the TryFrom<u64> implementation for Int, except that it returns an Option instead of a Result.

Examples

Basic usage:

assert_eq!(Int::new(js_int::MIN_SAFE_INT), Some(Int::MIN));
assert_eq!(Int::new(js_int::MAX_SAFE_INT), Some(Int::MAX));
assert_eq!(Int::new(js_int::MIN_SAFE_INT - 1), None);
assert_eq!(Int::new(js_int::MAX_SAFE_INT + 1), None);

pub fn from_str_radix(src: &str, radix: u32) -> Result<Int, 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

This function panics if radix is not in the range from 2 to 36.

Examples

Basic usage:

assert_eq!(Int::from_str_radix("A", 16), Ok(int!(10)));

#[must_use]pub const fn min_value() -> Int

👎 Deprecated:

Use UInt::MIN instead.

Returns the smallest value that can be represented by this integer type.

Examples

Basic usage:

assert_eq!(Int::min_value(), Int::try_from(-9_007_199_254_740_991i64).unwrap());

#[must_use]pub const fn max_value() -> Int

👎 Deprecated:

Use Int::MAX instead.

Returns the largest value that can be represented by this integer type.

Examples

Basic usage:

assert_eq!(Int::max_value(), Int::try_from(9_007_199_254_740_991i64).unwrap());

#[must_use]pub fn abs(self) -> Int

Computes the absolute value of self.

Examples

Basic usage:

assert_eq!(int!(10).abs(), int!(10));
assert_eq!(int!(-10).abs(), int!(10));

// Differently from i8 / i16 / i32 / i128, Int's min_value is its max_value negated
assert_eq!(Int::MIN.abs(), Int::MAX);

#[must_use]pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

Examples

Basic usage:

assert!(int!(10).is_positive());
assert!(!int!(0).is_positive());
assert!(!int!(-10).is_positive());

#[must_use]pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

Examples

Basic usage:

assert!(int!(-10).is_negative());
assert!(!int!(0).is_negative());
assert!(!int!(10).is_negative());

#[must_use]pub fn checked_add(self, rhs: Int) -> Option<Int>

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

Examples

Basic usage:

assert_eq!(
    (Int::MAX - int!(1)).checked_add(int!(1)),
    Some(Int::MAX)
);
assert_eq!((Int::MAX - int!(1)).checked_add(int!(2)), None);

#[must_use]pub fn checked_sub(self, rhs: Int) -> Option<Int>

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

Examples

Basic usage:

assert_eq!(
    (Int::MIN + int!(2)).checked_sub(int!(1)),
    Some(Int::MIN + int!(1))
);
assert_eq!((Int::MIN + int!(2)).checked_sub(int!(3)), None);

#[must_use]pub fn checked_mul(self, rhs: Int) -> Option<Int>

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

Examples

Basic usage:

assert_eq!(int!(5).checked_mul(int!(1)), Some(int!(5)));
assert_eq!(Int::MAX.checked_mul(int!(2)), None);

#[must_use]pub fn checked_div(self, rhs: Int) -> Option<Int>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

Examples

Basic usage:

assert_eq!(Int::MIN.checked_div(int!(-1)), Some(Int::MAX));
assert_eq!(int!(1).checked_div(int!(0)), None);

#[must_use]pub fn checked_rem(self, rhs: Int) -> Option<Int>

Checked integer remainder. Computes self % rhs, returning None if rhs == 0.

Examples

Basic usage:

assert_eq!(int!(5).checked_rem(int!(2)), Some(int!(1)));
assert_eq!(int!(5).checked_rem(int!(0)), None);
assert_eq!(Int::MIN.checked_rem(int!(-1)), Some(int!(0)));

#[must_use]pub fn checked_pow(self, exp: u32) -> Option<Int>

Checked exponentiation. Computes self.pow(exp), returning None if overflow or underflow occurred.

Examples

Basic usage:

assert_eq!(int!(8).checked_pow(2), Some(int!(64)));
assert_eq!(Int::MAX.checked_pow(2), None);
assert_eq!(Int::MIN.checked_pow(2), None);
assert_eq!(int!(1_000_000_000).checked_pow(2), None);

#[must_use]pub fn saturating_add(self, rhs: Int) -> Int

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

Examples

Basic usage:

assert_eq!(int!(100).saturating_add(int!(1)), int!(101));
assert_eq!(Int::MAX.saturating_add(int!(1)), Int::MAX);

#[must_use]pub fn saturating_sub(self, rhs: Int) -> Int

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

Examples

Basic usage:

assert_eq!(int!(100).saturating_sub(int!(1)), int!(99));
assert_eq!(Int::MIN.saturating_sub(int!(1)), Int::MIN);

#[must_use]pub fn saturating_mul(self, rhs: Int) -> Int

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

Examples

Basic usage:

assert_eq!(int!(100).saturating_mul(int!(2)), int!(200));
assert_eq!(Int::MAX.saturating_mul(int!(2)), Int::MAX);
assert_eq!(Int::MAX.saturating_mul(Int::MAX), Int::MAX);
assert_eq!(Int::MAX.saturating_mul(Int::MIN), Int::MIN);

#[must_use]pub fn saturating_pow(self, exp: u32) -> Int

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing or underflowing.

Examples

Basic usage:

assert_eq!(int!(5).saturating_pow(2), int!(25));
assert_eq!(int!(-2).saturating_pow(3), int!(-8));
assert_eq!(Int::MAX.saturating_pow(2), Int::MAX);
assert_eq!(Int::MIN.saturating_pow(2), Int::MAX);

Trait Implementations

impl Add<Int> for Int

type Output = Int

The resulting type after applying the + operator.

impl AddAssign<Int> for Int

impl Clone for Int

impl Copy for Int

impl Debug for Int

impl Default for Int

impl<'de> Deserialize<'de> for Int

impl Display for Int

impl Div<Int> for Int

type Output = Int

The resulting type after applying the / operator.

impl DivAssign<Int> for Int

impl Eq for Int

impl From<Int> for f64

impl From<Int> for i64

impl From<Int> for i128

impl From<UInt> for Int

impl From<i16> for Int

impl From<i32> for Int

impl From<i8> for Int

impl From<u16> for Int

impl From<u32> for Int

impl From<u8> for Int

impl FromStr for Int

type Err = ParseIntError

The associated error which can be returned from parsing.

impl Hash for Int

impl Mul<Int> for Int

type Output = Int

The resulting type after applying the * operator.

impl MulAssign<Int> for Int

impl Neg for Int

type Output = Int

The resulting type after applying the - operator.

impl Ord for Int

impl PartialEq<Int> for Int

impl PartialOrd<Int> for Int

impl<'a> Product<&'a Int> for Int

impl Product<Int> for Int

impl Rem<Int> for Int

type Output = Int

The resulting type after applying the % operator.

impl RemAssign<Int> for Int

impl Serialize for Int

impl StructuralEq for Int

impl StructuralPartialEq for Int

impl Sub<Int> for Int

type Output = Int

The resulting type after applying the - operator.

impl SubAssign<Int> for Int

impl<'a> Sum<&'a Int> for Int

impl Sum<Int> for Int

impl TryFrom<Int> for i16

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<Int> for i32

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<Int> for i8

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i128> for Int

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i64> for Int

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u128> for Int

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u64> for Int

type Error = TryFromIntError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> AsyncTraitDeps for T where
    T: Send + Sync + Debug
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CallHasher for T where
    T: Hash

impl<T> CallHasher for T where
    T: Hash + ?Sized

impl<T> Conv for T

impl<T> Conv for T

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

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,