num::traits

Trait CheckedRem

Source
pub trait CheckedRem: Sized + Rem<Output = Self> {
    // Required method
    fn checked_rem(&self, v: &Self) -> Option<Self>;
}
Expand description

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

Required Methods§

Source

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

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

§Examples
use num_traits::CheckedRem;
use std::i32::MIN;

assert_eq!(CheckedRem::checked_rem(&10, &7), Some(3));
assert_eq!(CheckedRem::checked_rem(&10, &-7), Some(3));
assert_eq!(CheckedRem::checked_rem(&-10, &7), Some(-3));
assert_eq!(CheckedRem::checked_rem(&-10, &-7), Some(-3));

assert_eq!(CheckedRem::checked_rem(&10, &0), None);

assert_eq!(CheckedRem::checked_rem(&MIN, &1), Some(0));
assert_eq!(CheckedRem::checked_rem(&MIN, &-1), None);

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

Source§

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

Source§

impl CheckedRem for i16

Source§

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

Source§

impl CheckedRem for i32

Source§

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

Source§

impl CheckedRem for i64

Source§

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

Source§

impl CheckedRem for i128

Source§

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

Source§

impl CheckedRem for isize

Source§

impl CheckedRem for u8

Source§

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

Source§

impl CheckedRem for u16

Source§

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

Source§

impl CheckedRem for u32

Source§

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

Source§

impl CheckedRem for u64

Source§

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

Source§

impl CheckedRem for u128

Source§

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

Source§

impl CheckedRem for usize

Implementors§