Trait IntegerSubset

Source
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§

Source

type Signed: Integer + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>

This type’s corresponding signed Integer representation

Implementors should guarantee that this type has the same theoretical bit precision as the Unsigned type

Source

type Unsigned: Natural + IntegerSubset<Signed = Self::Signed, Unsigned = Self::Unsigned>

This type’s corresponding unsigned Integer representation

Implementors should guarantee that this type has the same theoretical bit precision as the Signed type

Required Methods§

Source

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

Source

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§

Source

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

Source

fn two() -> Self

A shorthand for 1+1

Source

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

Source

fn div_two(self) -> Self

Divides 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 division

Source

fn even(&self) -> bool

Determines if a number is divisible by two

Source

fn odd(&self) -> bool

Determines if a number is not divisible by two

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.

Implementations on Foreign Types§

Source§

impl IntegerSubset for i8

Source§

type Signed = i8

Source§

type Unsigned = u8

Source§

fn as_signed(self) -> i8

Source§

fn as_unsigned(self) -> u8

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for i16

Source§

type Signed = i16

Source§

type Unsigned = u16

Source§

fn as_signed(self) -> i16

Source§

fn as_unsigned(self) -> u16

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for i32

Source§

type Signed = i32

Source§

type Unsigned = u32

Source§

fn as_signed(self) -> i32

Source§

fn as_unsigned(self) -> u32

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for i64

Source§

type Signed = i64

Source§

type Unsigned = u64

Source§

fn as_signed(self) -> i64

Source§

fn as_unsigned(self) -> u64

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for i128

Source§

type Signed = i128

Source§

type Unsigned = u128

Source§

fn as_signed(self) -> i128

Source§

fn as_unsigned(self) -> u128

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for isize

Source§

type Signed = isize

Source§

type Unsigned = usize

Source§

fn as_signed(self) -> isize

Source§

fn as_unsigned(self) -> usize

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for u8

Source§

type Signed = i8

Source§

type Unsigned = u8

Source§

fn as_signed(self) -> i8

Source§

fn as_unsigned(self) -> u8

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for u16

Source§

type Signed = i16

Source§

type Unsigned = u16

Source§

fn as_signed(self) -> i16

Source§

fn as_unsigned(self) -> u16

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for u32

Source§

type Signed = i32

Source§

type Unsigned = u32

Source§

fn as_signed(self) -> i32

Source§

fn as_unsigned(self) -> u32

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for u64

Source§

type Signed = i64

Source§

type Unsigned = u64

Source§

fn as_signed(self) -> i64

Source§

fn as_unsigned(self) -> u64

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for u128

Source§

type Signed = i128

Source§

type Unsigned = u128

Source§

fn as_signed(self) -> i128

Source§

fn as_unsigned(self) -> u128

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Source§

impl IntegerSubset for usize

Source§

type Signed = isize

Source§

type Unsigned = usize

Source§

fn as_signed(self) -> isize

Source§

fn as_unsigned(self) -> usize

Source§

fn two() -> Self

Source§

fn mul_two(self) -> Self

Source§

fn div_two(self) -> Self

Source§

fn even(&self) -> bool

Source§

fn odd(&self) -> bool

Implementors§