num_traits::ops::euclid

Trait CheckedEuclid

Source
pub trait CheckedEuclid: Euclid {
    // Required methods
    fn checked_div_euclid(&self, v: &Self) -> Option<Self>;
    fn checked_rem_euclid(&self, v: &Self) -> Option<Self>;

    // Provided method
    fn checked_div_rem_euclid(&self, v: &Self) -> Option<(Self, Self)> { ... }
}

Required Methods§

Source

fn checked_div_euclid(&self, v: &Self) -> Option<Self>

Performs euclid division that returns None instead of panicking on division by zero and instead of wrapping around on underflow and overflow.

Source

fn checked_rem_euclid(&self, v: &Self) -> Option<Self>

Finds the euclid remainder of dividing two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned.

Provided Methods§

Source

fn checked_div_rem_euclid(&self, v: &Self) -> Option<(Self, Self)>

Returns both the quotient and remainder from checked Euclidean division.

By default, it internally calls both CheckedEuclid::checked_div_euclid and CheckedEuclid::checked_rem_euclid, but it can be overridden in order to implement some optimization.

§Examples
let x = 5u8;
let y = 3u8;

let div = CheckedEuclid::checked_div_euclid(&x, &y);
let rem = CheckedEuclid::checked_rem_euclid(&x, &y);

assert_eq!(Some((div.unwrap(), rem.unwrap())), CheckedEuclid::checked_div_rem_euclid(&x, &y));

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

Source§

fn checked_div_euclid(&self, v: &i8) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &i8) -> Option<Self>

Source§

impl CheckedEuclid for i16

Source§

fn checked_div_euclid(&self, v: &i16) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &i16) -> Option<Self>

Source§

impl CheckedEuclid for i32

Source§

fn checked_div_euclid(&self, v: &i32) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &i32) -> Option<Self>

Source§

impl CheckedEuclid for i64

Source§

fn checked_div_euclid(&self, v: &i64) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &i64) -> Option<Self>

Source§

impl CheckedEuclid for i128

Source§

fn checked_div_euclid(&self, v: &i128) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &i128) -> Option<Self>

Source§

impl CheckedEuclid for isize

Source§

fn checked_div_euclid(&self, v: &isize) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &isize) -> Option<Self>

Source§

impl CheckedEuclid for u8

Source§

fn checked_div_euclid(&self, v: &u8) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &u8) -> Option<Self>

Source§

impl CheckedEuclid for u16

Source§

fn checked_div_euclid(&self, v: &u16) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &u16) -> Option<Self>

Source§

impl CheckedEuclid for u32

Source§

fn checked_div_euclid(&self, v: &u32) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &u32) -> Option<Self>

Source§

impl CheckedEuclid for u64

Source§

fn checked_div_euclid(&self, v: &u64) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &u64) -> Option<Self>

Source§

impl CheckedEuclid for u128

Source§

fn checked_div_euclid(&self, v: &u128) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &u128) -> Option<Self>

Source§

impl CheckedEuclid for usize

Source§

fn checked_div_euclid(&self, v: &usize) -> Option<Self>

Source§

fn checked_rem_euclid(&self, v: &usize) -> Option<Self>

Implementors§