pub trait PrimInt:
Sized
+ Copy
+ PrimBits
+ Num
+ NumCast
+ Bounded
+ PartialOrd
+ Ord
+ Eq
+ CheckedAdd<Output = Self>
+ CheckedSub<Output = Self>
+ CheckedMul<Output = Self>
+ CheckedDiv<Output = Self>
+ Saturating {
// Required method
fn pow(self, exp: u32) -> Self;
}Expand description
Generic trait for primitive integers.
The PrimInt trait is an abstraction over the builtin primitive integer types (e.g., u8,
u32, isize, i128, …). It inherits the basic numeric traits and extends them with
bitwise operators and non-wrapping arithmetic.
The trait explicitly inherits Copy, Eq, Ord, and Sized. The intention is that all
types implementing this trait behave like primitive types that are passed by value by default
and behave like builtin integers. Furthermore, the types are expected to expose the integer
value in binary representation and support bitwise operators. The standard bitwise operations
(e.g., bitwise-and, bitwise-or, right-shift, left-shift) are inherited, and the bit-level
introspection methods (e.g., count_ones(), leading_zeros()), bitwise combinators (e.g.,
rotate_left()), and endianness converters (e.g., to_be()) come from the PrimBits
supertrait.
All PrimInt types are expected to be fixed-width binary integers. The width can be queried
via T::zero().count_zeros(). The trait currently lacks a way to query the width at
compile-time.
While a default implementation for all builtin primitive integers is provided, the trait is in no way restricted to these. Other integer types that fulfil the requirements are free to implement the trait was well.
Types that cannot expose comparison or division (e.g. constant-time
integers) should implement only PrimBits; PrimInt adds the
Ord/Num/checked-arithmetic capabilities on top.
This trait and many of the method names originate in the unstable core::num::Int trait from
the rust standard library. The original trait was never stabilized and thus removed from the
standard library.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".