[]Struct matrix_sdk_base::UInt

pub struct UInt(_);

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

Implementations

impl UInt

pub const MIN: UInt

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

Examples

Basic usage:

assert_eq!(UInt::MIN, uint!(0));

pub const MAX: UInt

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

Examples

Basic usage:

assert_eq!(UInt::MAX, UInt::try_from(9_007_199_254_740_991u64).unwrap());

#[must_use]pub fn new(val: u64) -> Option<UInt>

Try to create a UInt from the provided u64, returning None if it is larger than MAX_SAFE_UINT.

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

Examples

Basic usage:

assert_eq!(UInt::new(js_int::MAX_SAFE_UINT), Some(UInt::MAX));
assert_eq!(UInt::new(js_int::MAX_SAFE_UINT + 1), None);

#[must_use]pub fn new_wrapping(val: u64) -> UInt

Create a UInt from the provided u64, wrapping at MAX_SAFE_UINT.

Examples

Basic usage:

assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT), UInt::MAX);
assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT + 1), uint!(0));

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

👎 Deprecated:

Use UInt::MIN instead.

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

Examples

Basic usage:

assert_eq!(UInt::min_value(), uint!(0));

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

👎 Deprecated:

Use UInt::MAX instead.

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

Examples

Basic usage:

assert_eq!(UInt::max_value(), UInt::try_from(9_007_199_254_740_991u64).unwrap());

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

Returns true if and only if self == 2^k for some k.

Examples

Basic usage:

assert!(uint!(16).is_power_of_two());
assert!(!uint!(10).is_power_of_two());

#[must_use]pub fn checked_next_power_of_two(self) -> Option<UInt>

Returns the smallest power of two greater than or equal to n. If the next power of two is greater than the type's maximum value, None is returned, otherwise the power of two is wrapped in Some.

Examples

Basic usage:

assert_eq!(uint!(2).checked_next_power_of_two(), Some(uint!(2)));
assert_eq!(uint!(3).checked_next_power_of_two(), Some(uint!(4)));
assert_eq!(UInt::MAX.checked_next_power_of_two(), None);

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

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

The string is expected to be an optional + 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!(UInt::from_str_radix("A", 16), Ok(uint!(10)));

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

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

assert_eq!(
    (UInt::MAX - uint!(2)).checked_add(uint!(1)),
    Some(UInt::MAX - uint!(1))
);
assert_eq!((UInt::MAX - uint!(2)).checked_add(uint!(3)), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(1).checked_sub(uint!(1)), Some(uint!(0)));
assert_eq!(uint!(0).checked_sub(uint!(1)), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(5).checked_mul(uint!(1)), Some(uint!(5)));
assert_eq!(UInt::MAX.checked_mul(uint!(2)), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(128).checked_div(uint!(2)), Some(uint!(64)));
assert_eq!(uint!(1).checked_div(uint!(0)), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(5).checked_rem(uint!(2)), Some(uint!(1)));
assert_eq!(uint!(5).checked_rem(uint!(0)), None);

#[must_use]pub fn checked_neg(self) -> Option<UInt>

Checked negation. Computes -self, returning None unless self == 0.

Note that negating any positive integer will overflow.

Examples

Basic usage:

assert_eq!(uint!(0).checked_neg(), Some(uint!(0)));
assert_eq!(uint!(1).checked_neg(), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(0).checked_pow(2), Some(uint!(0)));
assert_eq!(uint!(8).checked_pow(2), Some(uint!(64)));
assert_eq!(uint!(1_000_000_000u32).checked_pow(2), None);
assert_eq!(UInt::MAX.checked_pow(2), None);

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

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

Examples

Basic usage:

assert_eq!(uint!(100).saturating_add(uint!(1)), uint!(101));
assert_eq!(UInt::MAX.saturating_add(uint!(1)), UInt::MAX);

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

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

Examples

Basic usage:

assert_eq!(uint!(100).saturating_sub(uint!(1)), uint!(99));
assert_eq!(uint!(1).saturating_sub(uint!(2)), uint!(0));

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

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

Examples

Basic usage:

assert_eq!(uint!(100).saturating_mul(uint!(2)), uint!(200));
assert_eq!(UInt::MAX.saturating_mul(uint!(2)), UInt::MAX);
assert_eq!(UInt::MAX.saturating_mul(UInt::MAX), UInt::MAX);

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

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

Examples

Basic usage:

assert_eq!(uint!(5).saturating_pow(2), uint!(25));
assert_eq!(UInt::MAX.saturating_pow(2), UInt::MAX);

Trait Implementations

impl Add<UInt> for UInt

type Output = UInt

The resulting type after applying the + operator.

impl AddAssign<UInt> for UInt

impl Clone for UInt

impl Copy for UInt

impl Debug for UInt

impl Default for UInt

impl<'de> Deserialize<'de> for UInt

impl Display for UInt

impl Div<UInt> for UInt

type Output = UInt

The resulting type after applying the / operator.

impl DivAssign<UInt> for UInt

impl Eq for UInt

impl From<UInt> for i128

impl From<UInt> for u128

impl From<UInt> for u64

impl From<UInt> for Int

impl From<UInt> for f64

impl From<UInt> for i64

impl From<UInt> for RoomMemberCountIs

impl From<u16> for UInt

impl From<u32> for UInt

impl From<u8> for UInt

impl FromStr for UInt

type Err = ParseIntError

The associated error which can be returned from parsing.

impl Hash for UInt

impl Mul<UInt> for UInt

type Output = UInt

The resulting type after applying the * operator.

impl MulAssign<UInt> for UInt

impl Ord for UInt

impl PartialEq<UInt> for UInt

impl PartialOrd<UInt> for UInt

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

impl Product<UInt> for UInt

impl RangeBounds<UInt> for RoomMemberCountIs

impl Rem<UInt> for UInt

type Output = UInt

The resulting type after applying the % operator.

impl RemAssign<UInt> for UInt

impl Serialize for UInt

impl StructuralEq for UInt

impl StructuralPartialEq for UInt

impl Sub<UInt> for UInt

type Output = UInt

The resulting type after applying the - operator.

impl SubAssign<UInt> for UInt

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

impl Sum<UInt> for UInt

impl TryFrom<UInt> for u16

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<UInt> for u32

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<UInt> for u8

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i128> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i16> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i32> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i64> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i8> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u128> for UInt

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u64> for UInt

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