[−][src]Struct js_int::UInt
An integer limited to the range of non-negative integers that can be represented exactly by an f64.
Implementations
impl UInt
[src]
pub const MIN: Self
[src]
The smallest value that can be represented by this integer type.
Examples
Basic usage:
assert_eq!(UInt::MIN, uint!(0));
pub const MAX: Self
[src]
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<Self>
[src]
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) -> Self
[src]
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() -> Self
[src]
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() -> Self
[src]
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
[src]
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<Self>
[src]
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<Self, ParseIntError>
[src]
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: Self) -> Option<Self>
[src]
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: Self) -> Option<Self>
[src]
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: Self) -> Option<Self>
[src]
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: Self) -> Option<Self>
[src]
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: Self) -> Option<Self>
[src]
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<Self>
[src]
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<Self>
[src]
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: Self) -> Self
[src]
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: Self) -> Self
[src]
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: Self) -> Self
[src]
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) -> Self
[src]
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
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
impl AddAssign<UInt> for UInt
[src]
fn add_assign(&mut self, other: Self)
[src]
impl Clone for UInt
[src]
impl Copy for UInt
[src]
impl Debug for UInt
[src]
impl Default for UInt
[src]
impl Display for UInt
[src]
impl Div<UInt> for UInt
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Self
[src]
impl DivAssign<UInt> for UInt
[src]
fn div_assign(&mut self, other: Self)
[src]
impl Eq for UInt
[src]
impl From<UInt> for u64
[src]
impl From<UInt> for u128
[src]
impl From<UInt> for f64
[src]
impl From<u16> for UInt
[src]
impl From<u32> for UInt
[src]
impl From<u8> for UInt
[src]
impl FromStr for UInt
[src]
type Err = ParseIntError
The associated error which can be returned from parsing.
fn from_str(src: &str) -> Result<Self, Self::Err>
[src]
impl Hash for UInt
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Mul<UInt> for UInt
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self
[src]
impl MulAssign<UInt> for UInt
[src]
fn mul_assign(&mut self, other: Self)
[src]
impl Ord for UInt
[src]
fn cmp(&self, other: &UInt) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<UInt> for UInt
[src]
impl PartialOrd<UInt> for UInt
[src]
fn partial_cmp(&self, other: &UInt) -> Option<Ordering>
[src]
fn lt(&self, other: &UInt) -> bool
[src]
fn le(&self, other: &UInt) -> bool
[src]
fn gt(&self, other: &UInt) -> bool
[src]
fn ge(&self, other: &UInt) -> bool
[src]
impl<'a> Product<&'a UInt> for UInt
[src]
impl Product<UInt> for UInt
[src]
impl Rem<UInt> for UInt
[src]
type Output = Self
The resulting type after applying the %
operator.
fn rem(self, rhs: Self) -> Self
[src]
impl RemAssign<UInt> for UInt
[src]
fn rem_assign(&mut self, other: Self)
[src]
impl StructuralEq for UInt
[src]
impl StructuralPartialEq for UInt
[src]
impl Sub<UInt> for UInt
[src]
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
impl SubAssign<UInt> for UInt
[src]
fn sub_assign(&mut self, other: Self)
[src]
impl<'a> Sum<&'a UInt> for UInt
[src]
impl Sum<UInt> for UInt
[src]
impl TryFrom<UInt> for u8
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: UInt) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<UInt> for u16
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: UInt) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<UInt> for u32
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: UInt) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<i128> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: i128) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<i16> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: i16) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<i32> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: i32) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<i64> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: i64) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<i8> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: i8) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<u128> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: u128) -> Result<Self, TryFromIntError>
[src]
impl TryFrom<u64> for UInt
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(val: u64) -> Result<Self, TryFromIntError>
[src]
Auto Trait Implementations
impl RefUnwindSafe for UInt
impl Send for UInt
impl Sync for UInt
impl Unpin for UInt
impl UnwindSafe for UInt
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,