[][src]Trait funty::IsInteger

pub trait IsInteger: IsNumber + Hash + Eq + Ord + Binary + LowerHex + UpperHex + Octal + BitAnd<Self, Output = Self> + for<'a> BitAnd<&'a Self, Output = Self> + BitAndAssign<Self> + for<'a> BitAndAssign<&'a Self> + BitOr<Self, Output = Self> + for<'a> BitOr<&'a Self, Output = Self> + BitOrAssign<Self> + for<'a> BitOrAssign<&'a Self> + BitXor<Self, Output = Self> + for<'a> BitXor<&'a Self, Output = Self> + BitXorAssign<Self> + for<'a> BitXorAssign<&'a Self> + Not<Output = Self> + TryFrom<i8> + TryFrom<u8> + TryFrom<i16> + TryFrom<u16> + TryFrom<i32> + TryFrom<u32> + TryFrom<i64> + TryFrom<u64> + TryFrom<i128> + TryFrom<u128> + TryFrom<isize> + TryFrom<usize> + TryInto<i8> + TryInto<u8> + TryInto<i16> + TryInto<u16> + TryInto<i32> + TryInto<u32> + TryInto<i64> + TryInto<u64> + TryInto<i128> + TryInto<u128> + TryInto<isize> + TryInto<usize> + Shl<i8, Output = Self> + for<'a> Shl<&'a i8, Output = Self> + ShlAssign<i8> + for<'a> ShlAssign<&'a i8> + Shr<i8, Output = Self> + for<'a> Shr<&'a i8, Output = Self> + ShrAssign<i8> + for<'a> ShrAssign<&'a i8> + Shl<u8, Output = Self> + for<'a> Shl<&'a u8, Output = Self> + ShlAssign<u8> + for<'a> ShlAssign<&'a u8> + Shr<u8, Output = Self> + for<'a> Shr<&'a u8, Output = Self> + ShrAssign<u8> + for<'a> ShrAssign<&'a u8> + Shl<i16, Output = Self> + for<'a> Shl<&'a i16, Output = Self> + ShlAssign<i16> + for<'a> ShlAssign<&'a i16> + Shr<i16, Output = Self> + for<'a> Shr<&'a i16, Output = Self> + ShrAssign<i16> + for<'a> ShrAssign<&'a i16> + Shl<u16, Output = Self> + for<'a> Shl<&'a u16, Output = Self> + ShlAssign<u16> + for<'a> ShlAssign<&'a u16> + Shr<u16, Output = Self> + for<'a> Shr<&'a u16, Output = Self> + ShrAssign<u16> + for<'a> ShrAssign<&'a u16> + Shl<i32, Output = Self> + for<'a> Shl<&'a i32, Output = Self> + ShlAssign<i32> + for<'a> ShlAssign<&'a i32> + Shr<i32, Output = Self> + for<'a> Shr<&'a i32, Output = Self> + ShrAssign<i32> + for<'a> ShrAssign<&'a i32> + Shl<u32, Output = Self> + for<'a> Shl<&'a u32, Output = Self> + ShlAssign<u32> + for<'a> ShlAssign<&'a u32> + Shr<u32, Output = Self> + for<'a> Shr<&'a u32, Output = Self> + ShrAssign<u32> + for<'a> ShrAssign<&'a u32> + Shl<i64, Output = Self> + for<'a> Shl<&'a i64, Output = Self> + ShlAssign<i64> + for<'a> ShlAssign<&'a i64> + Shr<i64, Output = Self> + for<'a> Shr<&'a i64, Output = Self> + ShrAssign<i64> + for<'a> ShrAssign<&'a i64> + Shl<u64, Output = Self> + for<'a> Shl<&'a u64, Output = Self> + ShlAssign<u64> + for<'a> ShlAssign<&'a u64> + Shr<u64, Output = Self> + for<'a> Shr<&'a u64, Output = Self> + ShrAssign<u64> + for<'a> ShrAssign<&'a u64> + Shl<i128, Output = Self> + for<'a> Shl<&'a i128, Output = Self> + ShlAssign<i128> + for<'a> ShlAssign<&'a i128> + Shr<i128, Output = Self> + for<'a> Shr<&'a i128, Output = Self> + ShrAssign<i128> + for<'a> ShrAssign<&'a i128> + Shl<u128, Output = Self> + for<'a> Shl<&'a u128, Output = Self> + ShlAssign<u128> + for<'a> ShlAssign<&'a u128> + Shr<u128, Output = Self> + for<'a> Shr<&'a u128, Output = Self> + ShrAssign<u128> + for<'a> ShrAssign<&'a u128> + Shl<isize, Output = Self> + for<'a> Shl<&'a isize, Output = Self> + ShlAssign<isize> + for<'a> ShlAssign<&'a isize> + Shr<isize, Output = Self> + for<'a> Shr<&'a isize, Output = Self> + ShrAssign<isize> + for<'a> ShrAssign<&'a isize> + Shl<usize, Output = Self> + for<'a> Shl<&'a usize, Output = Self> + ShlAssign<usize> + for<'a> ShlAssign<&'a usize> + Shr<usize, Output = Self> + for<'a> Shr<&'a usize, Output = Self> + ShrAssign<usize> + for<'a> ShrAssign<&'a usize> {
    pub const ZERO: Self;
    pub const MIN: Self;
    pub const MAX: Self;

    pub fn min_value() -> Self;
pub fn max_value() -> Self;
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
pub fn count_ones(self) -> u32;
pub fn count_zeros(self) -> u32;
pub fn leading_zeros(self) -> u32;
pub fn trailing_zeros(self) -> u32;
pub fn leading_ones(self) -> u32;
pub fn trailing_ones(self) -> u32;
pub fn rotate_left(self, n: u32) -> Self;
pub fn rotate_right(self, n: u32) -> Self;
pub fn swap_bytes(self) -> Self;
pub fn reverse_bits(self) -> Self;
pub fn from_be(self) -> Self;
pub fn from_le(self) -> Self;
pub fn to_be(self) -> Self;
pub fn to_le(self) -> Self;
pub fn checked_add(self, rhs: Self) -> Option<Self>;
pub fn checked_sub(self, rhs: Self) -> Option<Self>;
pub fn checked_mul(self, rhs: Self) -> Option<Self>;
pub fn checked_div(self, rhs: Self) -> Option<Self>;
pub fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
pub fn checked_rem(self, rhs: Self) -> Option<Self>;
pub fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
pub fn checked_neg(self) -> Option<Self>;
pub fn checked_shl(self, rhs: u32) -> Option<Self>;
pub fn checked_shr(self, rhs: u32) -> Option<Self>;
pub fn checked_pow(self, rhs: u32) -> Option<Self>;
pub fn saturating_add(self, rhs: Self) -> Self;
pub fn saturating_sub(self, rhs: Self) -> Self;
pub fn saturating_mul(self, rhs: Self) -> Self;
pub fn saturating_pow(self, rhs: u32) -> Self;
pub fn wrapping_add(self, rhs: Self) -> Self;
pub fn wrapping_sub(self, rhs: Self) -> Self;
pub fn wrapping_mul(self, rhs: Self) -> Self;
pub fn wrapping_div(self, rhs: Self) -> Self;
pub fn wrapping_div_euclid(self, rhs: Self) -> Self;
pub fn wrapping_rem(self, rhs: Self) -> Self;
pub fn wrapping_rem_euclid(self, rhs: Self) -> Self;
pub fn wrapping_neg(self) -> Self;
pub fn wrapping_shl(self, rhs: u32) -> Self;
pub fn wrapping_shr(self, rhs: u32) -> Self;
pub fn wrapping_pow(self, rhs: u32) -> Self;
pub fn overflowing_add(self, rhs: Self) -> (Self, bool);
pub fn overflowing_sub(self, rhs: Self) -> (Self, bool);
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool);
pub fn overflowing_div(self, rhs: Self) -> (Self, bool);
pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool);
pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
pub fn overflowing_neg(self) -> (Self, bool);
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool);
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool);
pub fn overflowing_pow(self, rhs: u32) -> (Self, bool);
pub fn pow(self, rhs: u32) -> Self;
pub fn div_euclid(self, rhs: Self) -> Self;
pub fn rem_euclid(self, rhs: Self) -> Self; }

Declare that a type is a fixed-point integer.

This unifies all of the signed and unsigned integral types.

Associated Constants

pub const ZERO: Self[src]

The type’s zero value.

pub const MIN: Self[src]

The type’s minimum value. This is zero for unsigned integers.

pub const MAX: Self[src]

The type’s maximum value.

Loading content...

Required methods

pub fn min_value() -> Self[src]

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

pub fn max_value() -> Self[src]

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

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 + 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.

pub fn count_ones(self) -> u32[src]

Returns the number of ones in the binary representation of self.

pub fn count_zeros(self) -> u32[src]

Returns the number of zeros in the binary representation of self.

pub fn leading_zeros(self) -> u32[src]

Returns the number of leading zeros in the binary representation of self.

pub fn trailing_zeros(self) -> u32[src]

Returns the number of trailing zeros in the binary representation of self.

pub fn leading_ones(self) -> u32[src]

Returns the number of leading ones in the binary representation of self.

pub fn trailing_ones(self) -> u32[src]

Returns the number of trailing ones in the binary representation of self.

pub fn rotate_left(self, n: u32) -> Self[src]

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

pub fn rotate_right(self, n: u32) -> Self[src]

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

pub fn swap_bytes(self) -> Self[src]

Reverses the byte order of the integer.

pub fn reverse_bits(self) -> Self[src]

Reverses the bit pattern of the integer.

pub fn from_be(self) -> Self[src]

Converts an integer from big endian to the target’s endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

pub fn from_le(self) -> Self[src]

Converts an integer frm little endian to the target’s endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

pub fn to_be(self) -> Self[src]

Converts self to big endian from the target’s endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

pub fn to_le(self) -> Self[src]

Converts self to little endian from the target’s endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

pub fn checked_add(self, rhs: Self) -> Option<Self>[src]

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

pub fn checked_sub(self, rhs: Self) -> Option<Self>[src]

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

pub fn checked_mul(self, rhs: Self) -> Option<Self>[src]

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

pub fn checked_div(self, rhs: Self) -> Option<Self>[src]

Checked integer division. Computes self / rhs, returning None if rhs == 0 or the division results in overflow.

pub fn checked_div_euclid(self, rhs: Self) -> Option<Self>[src]

Checked Euclidean division. Computes self.div_euclid(rhs), returning None if rhs == 0 or the division results in overflow.

pub fn checked_rem(self, rhs: Self) -> Option<Self>[src]

Checked integer remainder. Computes self % rhs, returning None if rhs == 0 or the division results in overflow.

pub fn checked_rem_euclid(self, rhs: Self) -> Option<Self>[src]

Checked Euclidean remainder. Computes self.rem_euclid(rhs), returning None if rhs == 0 or the division results in overflow.

pub fn checked_neg(self) -> Option<Self>[src]

Checked negation. Computes -self, returning None if self == MIN.

Note that negating any positive integer will overflow.

pub fn checked_shl(self, rhs: u32) -> Option<Self>[src]

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

pub fn checked_shr(self, rhs: u32) -> Option<Self>[src]

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

pub fn checked_pow(self, rhs: u32) -> Option<Self>[src]

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

pub fn saturating_add(self, rhs: Self) -> Self[src]

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

pub fn saturating_sub(self, rhs: Self) -> Self[src]

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

pub fn saturating_mul(self, rhs: Self) -> Self[src]

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

pub fn saturating_pow(self, rhs: u32) -> Self[src]

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

pub fn wrapping_add(self, rhs: Self) -> Self[src]

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

pub fn wrapping_sub(self, rhs: Self) -> Self[src]

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

pub fn wrapping_mul(self, rhs: Self) -> Self[src]

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

pub fn wrapping_div(self, rhs: Self) -> Self[src]

Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.

Signed Integers

The only case where such wrapping can occur is when one divides MIN / -1 on a signed type (where MIN is the negative minimal value for the type); this is equivalent to -MIN, a positive value that is too large to represent in the type. In such a case, this function returns MIN itself.

Unsigned Integers

Wrapping (modular) division. Computes self / rhs. Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.

Panics

This function will panic if rhs is 0.

pub fn wrapping_div_euclid(self, rhs: Self) -> Self[src]

Wrapping Eulidean division. Computes self.div_euclid(rhs), wrapping around at the boundary of the type.

Signed Types

Wrapping will only occur in MIN / -1 on a signed type (where MIN is the negative minimal value for the type). This is equivalent to -MIN, a positive value that is too large to represent in the type. In this case, this method returns MIN itself.

Unsigned Types

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.wrapping_div(rhs).

Panics

This function will panic if rhs is 0.

pub fn wrapping_rem(self, rhs: Self) -> Self[src]

Wrapping (modular) remainder. Computes self % rhs, wrapping around at the boundary of the type.

Signed Integers

Such wrap-around never actually occurs mathematically; implementation artifacts make x % y invalid for MIN / -1 on a signed type (where MIN is the negative minimal value). In such a case, this function returns 0.

Unsigned Integers

Wrapped remainder calculation on unsigned types is just the regular remainder calculation. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.

Panics

This function will panic if rhs is 0.

pub fn wrapping_rem_euclid(self, rhs: Self) -> Self[src]

Wrapping Euclidean remainder. Computes self.rem_euclid(rhs), wrapping around at the boundary of the type.

Signed Integers

Wrapping will only occur in MIN % -1 on a signed type (where MIN is the negative minimal value for the type). In this case, this method returns 0.

Unsigned Integers

Wrapped modulo calculation on unsigned types is just the regular remainder calculation. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.wrapping_rem(rhs).

Panics

This function will panic if rhs is 0.

pub fn wrapping_neg(self) -> Self[src]

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type.

Signed Integers

The only case where such wrapping can occur is when one negates MIN on a signed type (where MIN is the negative minimal value for the type); this is a positive value that is too large to represent in the type. In such a case, this function returns MIN itself.

Unsigned Integers

Since unsigned types do not have negative equivalents all applications of this function will wrap (except for -0). For values smaller than the corresponding signed type’s maximum the result is the same as casting the corresponding signed value. Any larger values are equivalent to MAX + 1 - (val - MAX - 1) where MAX is the corresponding signed type’s maximum.

pub fn wrapping_shl(self, rhs: u32) -> Self[src]

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The primitive integer types all implement a rotate_left function, which may be what you want instead.

pub fn wrapping_shr(self, rhs: u32) -> Self[src]

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The primitive integer types all implement a rotate_right function, which may be what you want instead.

pub fn wrapping_pow(self, rhs: u32) -> Self[src]

Wrapping (modular) exponentiation. Computes self.pow(exp), wrapping around at the boundary of the type.

pub fn overflowing_add(self, rhs: Self) -> (Self, bool)[src]

Calculates self + rhs

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

pub fn overflowing_sub(self, rhs: Self) -> (Self, bool)[src]

Calculates self - rhs

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

pub fn overflowing_mul(self, rhs: Self) -> (Self, bool)[src]

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

pub fn overflowing_div(self, rhs: Self) -> (Self, bool)[src]

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then self is returned.

Panics

This function will panic if rhs is 0.

pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)[src]

Calculates the quotient of Euclidean division self.div_euclid(rhs).

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then self is returned.

Panics

This function will panic if rhs is 0.

pub fn overflowing_rem(self, rhs: Self) -> (Self, bool)[src]

Calculates the remainder when self is divided by rhs.

Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.

Panics

This function will panic if rhs is 0.

pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)[src]

Overflowing Euclidean remainder. Calculates self.rem_euclid(rhs).

Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.

Panics

This function will panic if rhs is 0.

pub fn overflowing_neg(self) -> (Self, bool)[src]

Negates self, overflowing if this is equal to the minimum value.

Returns a tuple of the negated version of self along with a boolean indicating whether an overflow happened. If self is the minimum value (e.g., i32::MIN for values of type i32), then the minimum value will be returned again and true will be returned for an overflow happening.

pub fn overflowing_shl(self, rhs: u32) -> (Self, bool)[src]

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

pub fn overflowing_shr(self, rhs: u32) -> (Self, bool)[src]

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

pub fn overflowing_pow(self, rhs: u32) -> (Self, bool)[src]

Raises self to the power of exp, using exponentiation by squaring.

Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.

pub fn pow(self, rhs: u32) -> Self[src]

Raises self to the power of exp, using exponentiation by squaring.

pub fn div_euclid(self, rhs: Self) -> Self[src]

Calculates the quotient of Euclidean division of self by rhs.

This computes the integer n such that self = n * rhs + self.rem_euclid(rhs), with 0 <= self.rem_euclid(rhs) < rhs.

In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs. If self > 0, this is equal to round towards zero (the default in Rust); if self < 0, this is equal to round towards +/- infinity.

Panics

This function will panic if rhs is 0 or the division results in overflow.

pub fn rem_euclid(self, rhs: Self) -> Self[src]

Calculates the least nonnegative remainder of self (mod rhs).

This is done as if by the Euclidean division algorithm -- given r = self.rem_euclid(rhs), self = rhs * self.div_euclid(rhs) + r, and 0 <= r < abs(rhs).

Panics

This function will panic if rhs is 0 or the division results in overflow.

Loading content...

Implementations on Foreign Types

impl IsInteger for i8[src]

impl IsInteger for i16[src]

impl IsInteger for i32[src]

impl IsInteger for i64[src]

impl IsInteger for i128[src]

impl IsInteger for isize[src]

impl IsInteger for u8[src]

impl IsInteger for u16[src]

impl IsInteger for u32[src]

impl IsInteger for u64[src]

impl IsInteger for u128[src]

impl IsInteger for usize[src]

Loading content...

Implementors

Loading content...