pub struct Int(_);Expand description
An integer limited to the range of integers that can be represented exactly by an f64.
Implementations
sourceimpl Int
 
impl Int
sourcepub const MIN: Self = Self(MIN_SAFE_INT)
 
pub const MIN: Self = Self(MIN_SAFE_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());sourcepub const MAX: Self = Self(MAX_SAFE_INT)
 
pub const MAX: Self = Self(MAX_SAFE_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());sourcepub fn new(val: i64) -> Option<Self>
 
pub fn new(val: i64) -> Option<Self>
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);sourcepub fn new_saturating(val: i64) -> Self
 
pub fn new_saturating(val: i64) -> Self
Creates an Int from the given i64 clamped to the safe interval.
The given value gets clamped into the closed interval between
MIN_SAFE_INT and MAX_SAFE_INT.
Examples
Basic usage:
assert_eq!(Int::new_saturating(0), int!(0));
assert_eq!(Int::new_saturating(js_int::MAX_SAFE_INT), Int::MAX);
assert_eq!(Int::new_saturating(js_int::MAX_SAFE_INT + 1), Int::MAX);
assert_eq!(Int::new_saturating(js_int::MIN_SAFE_INT), Int::MIN);
assert_eq!(Int::new_saturating(js_int::MIN_SAFE_INT - 1), Int::MIN);sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
 
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-9a-zA-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)));sourcepub const fn min_value() -> Self
 👎 Deprecated: Use UInt::MIN instead.
pub const fn min_value() -> Self
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());sourcepub const fn max_value() -> Self
 👎 Deprecated: Use Int::MAX instead.
pub const fn max_value() -> Self
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());sourcepub fn abs(self) -> Self
 
pub fn abs(self) -> Self
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);sourcepub const fn is_positive(self) -> bool
 
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());sourcepub const fn is_negative(self) -> bool
 
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());sourcepub fn checked_add(self, rhs: Self) -> Option<Self>
 
pub fn checked_add(self, rhs: Self) -> Option<Self>
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);sourcepub fn checked_sub(self, rhs: Self) -> Option<Self>
 
pub fn checked_sub(self, rhs: Self) -> Option<Self>
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);sourcepub fn checked_mul(self, rhs: Self) -> Option<Self>
 
pub fn checked_mul(self, rhs: Self) -> Option<Self>
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);sourcepub fn checked_div(self, rhs: Self) -> Option<Self>
 
pub fn checked_div(self, rhs: Self) -> Option<Self>
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);sourcepub fn checked_rem(self, rhs: Self) -> Option<Self>
 
pub fn checked_rem(self, rhs: Self) -> Option<Self>
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)));sourcepub fn checked_pow(self, exp: u32) -> Option<Self>
 
pub fn checked_pow(self, exp: u32) -> Option<Self>
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);sourcepub fn saturating_add(self, rhs: Self) -> Self
 
pub fn saturating_add(self, rhs: Self) -> Self
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);
assert_eq!(Int::MIN.saturating_add(int!(-1)), Int::MIN);sourcepub fn saturating_sub(self, rhs: Self) -> Self
 
pub fn saturating_sub(self, rhs: Self) -> Self
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);
assert_eq!(Int::MAX.saturating_sub(int!(-1)), Int::MAX);sourcepub fn saturating_mul(self, rhs: Self) -> Self
 
pub fn saturating_mul(self, rhs: Self) -> Self
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);sourcepub fn saturating_pow(self, exp: u32) -> Self
 
pub fn saturating_pow(self, exp: u32) -> Self
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
sourceimpl AddAssign<Int> for Int
 
impl AddAssign<Int> for Int
sourcefn add_assign(&mut self, other: Self)
 
fn add_assign(&mut self, other: Self)
Performs the += operation. Read more
sourceimpl<'de> Deserialize<'de> for Int
 
impl<'de> Deserialize<'de> for Int
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
    D: Deserializer<'de>, 
 
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
    D: Deserializer<'de>, 
Deserialize this value from the given Serde deserializer. Read more
sourceimpl DivAssign<Int> for Int
 
impl DivAssign<Int> for Int
sourcefn div_assign(&mut self, other: Self)
 
fn div_assign(&mut self, other: Self)
Performs the /= operation. Read more
sourceimpl MulAssign<Int> for Int
 
impl MulAssign<Int> for Int
sourcefn mul_assign(&mut self, other: Self)
 
fn mul_assign(&mut self, other: Self)
Performs the *= operation. Read more
sourceimpl Ord for Int
 
impl Ord for Int
sourceimpl PartialOrd<Int> for Int
 
impl PartialOrd<Int> for Int
sourcefn partial_cmp(&self, other: &Int) -> Option<Ordering>
 
fn partial_cmp(&self, other: &Int) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
 
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 · sourcefn le(&self, other: &Rhs) -> bool
 
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
sourceimpl RemAssign<Int> for Int
 
impl RemAssign<Int> for Int
sourcefn rem_assign(&mut self, other: Self)
 
fn rem_assign(&mut self, other: Self)
Performs the %= operation. Read more
sourceimpl SubAssign<Int> for Int
 
impl SubAssign<Int> for Int
sourcefn sub_assign(&mut self, other: Self)
 
fn sub_assign(&mut self, other: Self)
Performs the -= operation. Read more
sourceimpl TryFrom<Int> for i8
 
impl TryFrom<Int> for i8
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for u8
 
impl TryFrom<Int> for u8
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for i16
 
impl TryFrom<Int> for i16
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for u16
 
impl TryFrom<Int> for u16
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for i32
 
impl TryFrom<Int> for i32
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for u32
 
impl TryFrom<Int> for u32
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for isize
 
impl TryFrom<Int> for isize
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<Int> for usize
 
impl TryFrom<Int> for usize
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: Int) -> Result<Self, TryFromIntError>
 
fn try_from(val: Int) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<i128> for Int
 
impl TryFrom<i128> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: i128) -> Result<Self, TryFromIntError>
 
fn try_from(val: i128) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<i64> for Int
 
impl TryFrom<i64> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: i64) -> Result<Self, TryFromIntError>
 
fn try_from(val: i64) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<isize> for Int
 
impl TryFrom<isize> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: isize) -> Result<Self, TryFromIntError>
 
fn try_from(val: isize) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<u128> for Int
 
impl TryFrom<u128> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: u128) -> Result<Self, TryFromIntError>
 
fn try_from(val: u128) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<u64> for Int
 
impl TryFrom<u64> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: u64) -> Result<Self, TryFromIntError>
 
fn try_from(val: u64) -> Result<Self, TryFromIntError>
Performs the conversion.
sourceimpl TryFrom<usize> for Int
 
impl TryFrom<usize> for Int
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourcefn try_from(val: usize) -> Result<Self, TryFromIntError>
 
fn try_from(val: usize) -> Result<Self, TryFromIntError>
Performs the conversion.
impl Copy for Int
impl Eq for Int
impl StructuralEq for Int
impl StructuralPartialEq for Int
Auto Trait Implementations
impl RefUnwindSafe for Int
impl Send for Int
impl Sync for Int
impl Unpin for Int
impl UnwindSafe for Int
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more