pub trait CheckedRem: Sized + Rem<Self, 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§
Sourcefn checked_rem(&self, v: &Self) -> Option<Self>
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.