pub trait Integer:
Sized
+ Add<Self, Output = Self>
+ AddAssign
+ Sub<Self, Output = Self>
+ SubAssign
+ Shr<Self, Output = Self>
+ ShrAssign
+ Shl<Self, Output = Self>
+ ShlAssign
+ BitAnd<Self, Output = Self>
+ BitAndAssign
+ BitOr<Self, Output = Self>
+ BitOrAssign
+ BitXor<Self, Output = Self>
+ BitXorAssign
+ Div<Self, Output = Self>
+ DivAssign
+ Mul<Self, Output = Self>
+ MulAssign
+ Copy {
const MIN: Self;
const MAX: Self;
const BITS: u32;
Show 54 methods
// Required methods
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
fn count_ones(self) -> u32;
fn count_zeros(self) -> u32;
fn leading_zeros(self) -> u32;
fn trailing_zeros(self) -> u32;
fn leading_ones(self) -> u32;
fn trailing_ones(self) -> u32;
fn rotate_left(self, n: u32) -> Self;
fn rotate_right(self, n: u32) -> Self;
fn swap_bytes(self) -> Self;
fn reverse_bits(self) -> Self;
fn from_be(x: Self) -> Self;
fn from_le(x: Self) -> Self;
fn to_be(self) -> Self;
fn to_le(self) -> Self;
fn checked_add(self, rhs: Self) -> Option<Self>;
fn checked_sub(self, rhs: Self) -> Option<Self>;
fn checked_mul(self, rhs: Self) -> Option<Self>;
fn checked_div(self, rhs: Self) -> Option<Self>;
fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
fn checked_rem(self, rhs: Self) -> Option<Self>;
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
fn checked_neg(self) -> Option<Self>;
fn checked_shl(self, rhs: u32) -> Option<Self>;
fn checked_shr(self, rhs: u32) -> Option<Self>;
fn checked_pow(self, exp: u32) -> Option<Self>;
fn saturating_add(self, rhs: Self) -> Self;
fn saturating_sub(self, rhs: Self) -> Self;
fn saturating_mul(self, rhs: Self) -> Self;
fn saturating_pow(self, exp: u32) -> Self;
fn wrapping_add(self, rhs: Self) -> Self;
fn wrapping_sub(self, rhs: Self) -> Self;
fn wrapping_mul(self, rhs: Self) -> Self;
fn wrapping_div(self, rhs: Self) -> Self;
fn wrapping_div_euclid(self, rhs: Self) -> Self;
fn wrapping_rem(self, rhs: Self) -> Self;
fn wrapping_rem_euclid(self, rhs: Self) -> Self;
fn wrapping_neg(self) -> Self;
fn wrapping_shl(self, rhs: u32) -> Self;
fn wrapping_shr(self, rhs: u32) -> Self;
fn wrapping_pow(self, exp: u32) -> Self;
fn overflowing_add(self, rhs: Self) -> (Self, bool);
fn overflowing_sub(self, rhs: Self) -> (Self, bool);
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
fn overflowing_div(self, rhs: Self) -> (Self, bool);
fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
fn overflowing_rem(self, rhs: Self) -> (Self, bool);
fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
fn overflowing_neg(self) -> (Self, bool);
fn overflowing_shr(self, rhs: u32) -> (Self, bool);
fn overflowing_pow(self, exp: u32) -> (Self, bool);
fn pow(self, exp: u32) -> Self;
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
}
Expand description
Built-in integers interface exposed as a trait.
This trait is implemented for all the built-in integer types and copies their interface completely, so it’s possible to write generic code that accepts any integer number.
Interface includes all the trait implementations as well, such as Copy
, Add
or BitXorAssign
.
§Caveats
-
<to/from/as>_<be/ne/le>_bytes
are not implemented, as the return type (array of generic const length that depends on the trait itself) cannot in be expressed in stable rust. -
is_power_of_two
/next_power_of_two
/checked_next_power_of_two
methods are not implemented, as they exist for the unsigned numbers only.
Required Associated Constants§
Required Methods§
Sourcefn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
See u128::from_str_radix
.
Sourcefn count_ones(self) -> u32
fn count_ones(self) -> u32
See u128::count_ones
.
Sourcefn count_zeros(self) -> u32
fn count_zeros(self) -> u32
See u128::count_zeros
.
Sourcefn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
See u128::leading_zeros
.
Sourcefn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
See u128::trailing_zeros
.
Sourcefn leading_ones(self) -> u32
fn leading_ones(self) -> u32
See u128::leading_ones
.
Sourcefn trailing_ones(self) -> u32
fn trailing_ones(self) -> u32
See u128::trailing_ones
.
Sourcefn rotate_left(self, n: u32) -> Self
fn rotate_left(self, n: u32) -> Self
See u128::rotate_left
.
Sourcefn rotate_right(self, n: u32) -> Self
fn rotate_right(self, n: u32) -> Self
See u128::rotate_right
.
Sourcefn swap_bytes(self) -> Self
fn swap_bytes(self) -> Self
See u128::swap_bytes
.
Sourcefn reverse_bits(self) -> Self
fn reverse_bits(self) -> Self
See u128::reverse_bits
.
Sourcefn from_be(x: Self) -> Self
fn from_be(x: Self) -> Self
See u128::from_be
.
Sourcefn from_le(x: Self) -> Self
fn from_le(x: Self) -> Self
See u128::from_le
.
Sourcefn to_be(self) -> Self
fn to_be(self) -> Self
See u128::to_be
.
Sourcefn to_le(self) -> Self
fn to_le(self) -> Self
See u128::to_le
.
Sourcefn checked_add(self, rhs: Self) -> Option<Self>
fn checked_add(self, rhs: Self) -> Option<Self>
See u128::checked_add
.
Sourcefn checked_sub(self, rhs: Self) -> Option<Self>
fn checked_sub(self, rhs: Self) -> Option<Self>
See u128::checked_sub
.
Sourcefn checked_mul(self, rhs: Self) -> Option<Self>
fn checked_mul(self, rhs: Self) -> Option<Self>
See u128::checked_mul
.
Sourcefn checked_div(self, rhs: Self) -> Option<Self>
fn checked_div(self, rhs: Self) -> Option<Self>
See u128::checked_div
.
Sourcefn checked_div_euclid(self, rhs: Self) -> Option<Self>
fn checked_div_euclid(self, rhs: Self) -> Option<Self>
Sourcefn checked_rem(self, rhs: Self) -> Option<Self>
fn checked_rem(self, rhs: Self) -> Option<Self>
See u128::checked_rem
.
Sourcefn checked_rem_euclid(self, rhs: Self) -> Option<Self>
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>
Sourcefn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
See u128::checked_neg
.
Sourcefn checked_shl(self, rhs: u32) -> Option<Self>
fn checked_shl(self, rhs: u32) -> Option<Self>
See u128::checked_shl
.
Sourcefn checked_shr(self, rhs: u32) -> Option<Self>
fn checked_shr(self, rhs: u32) -> Option<Self>
See u128::checked_shr
.
Sourcefn checked_pow(self, exp: u32) -> Option<Self>
fn checked_pow(self, exp: u32) -> Option<Self>
See u128::checked_pow
.
Sourcefn saturating_add(self, rhs: Self) -> Self
fn saturating_add(self, rhs: Self) -> Self
See u128::saturating_add
.
Sourcefn saturating_sub(self, rhs: Self) -> Self
fn saturating_sub(self, rhs: Self) -> Self
See u128::saturating_sub
.
Sourcefn saturating_mul(self, rhs: Self) -> Self
fn saturating_mul(self, rhs: Self) -> Self
See u128::saturating_mul
.
Sourcefn saturating_pow(self, exp: u32) -> Self
fn saturating_pow(self, exp: u32) -> Self
See u128::saturating_pow
.
Sourcefn wrapping_add(self, rhs: Self) -> Self
fn wrapping_add(self, rhs: Self) -> Self
See u128::wrapping_add
.
Sourcefn wrapping_sub(self, rhs: Self) -> Self
fn wrapping_sub(self, rhs: Self) -> Self
See u128::wrapping_sub
.
Sourcefn wrapping_mul(self, rhs: Self) -> Self
fn wrapping_mul(self, rhs: Self) -> Self
See u128::wrapping_mul
.
Sourcefn wrapping_div(self, rhs: Self) -> Self
fn wrapping_div(self, rhs: Self) -> Self
See u128::wrapping_div
.
Sourcefn wrapping_div_euclid(self, rhs: Self) -> Self
fn wrapping_div_euclid(self, rhs: Self) -> Self
Sourcefn wrapping_rem(self, rhs: Self) -> Self
fn wrapping_rem(self, rhs: Self) -> Self
See u128::wrapping_rem
.
Sourcefn wrapping_rem_euclid(self, rhs: Self) -> Self
fn wrapping_rem_euclid(self, rhs: Self) -> Self
Sourcefn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
See u128::wrapping_neg
.
Sourcefn wrapping_shl(self, rhs: u32) -> Self
fn wrapping_shl(self, rhs: u32) -> Self
See u128::wrapping_shl
.
Sourcefn wrapping_shr(self, rhs: u32) -> Self
fn wrapping_shr(self, rhs: u32) -> Self
See u128::wrapping_shr
.
Sourcefn wrapping_pow(self, exp: u32) -> Self
fn wrapping_pow(self, exp: u32) -> Self
See u128::wrapping_pow
.
Sourcefn overflowing_add(self, rhs: Self) -> (Self, bool)
fn overflowing_add(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_sub(self, rhs: Self) -> (Self, bool)
fn overflowing_sub(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_mul(self, rhs: Self) -> (Self, bool)
fn overflowing_mul(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_div(self, rhs: Self) -> (Self, bool)
fn overflowing_div(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_rem(self, rhs: Self) -> (Self, bool)
fn overflowing_rem(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)
fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
Sourcefn overflowing_shr(self, rhs: u32) -> (Self, bool)
fn overflowing_shr(self, rhs: u32) -> (Self, bool)
Sourcefn overflowing_pow(self, exp: u32) -> (Self, bool)
fn overflowing_pow(self, exp: u32) -> (Self, bool)
Sourcefn div_euclid(self, rhs: Self) -> Self
fn div_euclid(self, rhs: Self) -> Self
See u128::div_euclid
.
Sourcefn rem_euclid(self, rhs: Self) -> Self
fn rem_euclid(self, rhs: Self) -> Self
See u128::rem_euclid
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.