Integer

Trait Integer 

Source
pub trait Integer: Number {
    // Required methods
    fn integer_is_even(&self) -> bool;
    fn integer_is_multiple_of(&self, other: &Self) -> bool;
    fn integer_is_prime(&self) -> Option<bool>;
    fn integer_gcd(&self, other: &Self) -> Option<Self>
       where Self: Sized;
    fn integer_lcm(&self, other: &Self) -> Option<Self>
       where Self: Sized;
    fn integer_digits(&self) -> usize;

    // Provided methods
    fn integer_is_odd(&self) -> bool { ... }
    fn integer_is_divisor_of(&self, other: &Self) -> bool { ... }
}
Expand description

Common trait for all integers.

Required Methods§

Source

fn integer_is_even(&self) -> bool

Returns true if this integer is even.

Source

fn integer_is_multiple_of(&self, other: &Self) -> bool

Returns true if this integer is a multiple of the other.

Source

fn integer_is_prime(&self) -> Option<bool>

Returns Some(true) if this integer is prime, Some(false) if it’s not prime, or None if it can not be determined.

Returns None if this integer can’t be represented as a usize, or as a u32 in no-std.

Source

fn integer_gcd(&self, other: &Self) -> Option<Self>
where Self: Sized,

Calculates the Greatest Common Divisor of this integer and other.

Returns None if the operation can’t return an integer of the same kind, e.g. for a NegativeInteger.

Source

fn integer_lcm(&self, other: &Self) -> Option<Self>
where Self: Sized,

Calculates the Lowest Common Multiple of this integer and other.

Returns None if the operation can’t return an integer of the same kind, e.g. for NegativeInteger.

Source

fn integer_digits(&self) -> usize

Returns the number of digits in base 10, without the sign.

Provided Methods§

Source

fn integer_is_odd(&self) -> bool

Returns true if this integer is odd.

Source

fn integer_is_divisor_of(&self, other: &Self) -> bool

Returns true if this integer is a divisor of the other.

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 Integer for i8

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for i16

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for i32

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for i64

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for i128

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for isize

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for u8

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for u16

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for u32

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for u64

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for u128

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for usize

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroI8

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroI16

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroI32

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroI64

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroI128

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroIsize

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroU8

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroU16

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroU32

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroU64

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroU128

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Source§

impl Integer for NonZeroUsize

Source§

fn integer_is_even(&self) -> bool

Source§

fn integer_is_multiple_of(&self, other: &Self) -> bool

Source§

fn integer_is_prime(&self) -> Option<bool>

Source§

fn integer_gcd(&self, other: &Self) -> Option<Self>

Source§

fn integer_lcm(&self, other: &Self) -> Option<Self>

Source§

fn integer_digits(&self) -> usize

Implementors§