pub trait IntegerSubset:
Ord
+ Eq
+ Clone
+ CastPrimInt
+ ToPrimitive
+ FromPrimitive
+ EuclideanSemidomain
+ Primality
+ ArchSemiring
+ ArchimedeanDiv
+ Sign
+ Sub<Self, Output = Self>
+ Div<Self, Output = Self>
+ Rem<Self, Output = Self>
+ SubAssign<Self>
+ DivAssign<Self>
+ RemAssign<Self> {
type Signed: Integer + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>;
type Unsigned: Natural + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>;
// Required methods
fn as_signed(self) -> Self::Signed;
fn as_unsigned(self) -> Self::Unsigned;
// Provided methods
fn abs_unsigned(self) -> Self::Unsigned { ... }
fn two() -> Self { ... }
fn mul_two(self) -> Self { ... }
fn div_two(self) -> Self { ... }
fn even(&self) -> bool { ... }
fn odd(&self) -> bool { ... }
}Expand description
A subset of the Integers that has all of the major integer operations
This includes:
- Basic ring operations
- Euclidean division any everything implied by having it
- Algebraic ordering properties and archimedian division
- Additional operations conventionally implemented on integer types
In practice, this means that a type implementing this trait must be either a representation of the natural numbers or the integers as a whole.
Furthermore, this trait contains associated types referring to an unsigned and signed type of similar precision to make it easier to manage the broader system of types used in integer algorithms
Required Associated Types§
Required Methods§
Sourcefn as_signed(self) -> Self::Signed
fn as_signed(self) -> Self::Signed
Converts self to a signed integer representation
Note that this has the same guarantees as the primitive as operation
and can thus panic on overflow
Sourcefn as_unsigned(self) -> Self::Unsigned
fn as_unsigned(self) -> Self::Unsigned
Converts self into an unsigned integer representation
Note that this has the same guarantees as the primitive as operation
and can thus panic on underflow
Provided Methods§
Sourcefn abs_unsigned(self) -> Self::Unsigned
fn abs_unsigned(self) -> Self::Unsigned
Takes the absolute value and converts into an unsigned integer representation
Implementors should guarantee that this conversion never fails or panics since the unsigned and signed types are assumed to be of the same theoretical bit precision
Sourcefn mul_two(self) -> Self
fn mul_two(self) -> Self
Multiplies by two
This is meant both as convenience and to expose the << operator for representations that
support it. As such, this method has the potential to be faster than normal multiplication
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.