Skip to main content

DivExact

Trait DivExact 

Source
pub trait DivExact:
    Sized
    + Div<Self>
    + Rem<Self> {
    // Required methods
    fn div_exact(self, rhs: Self) -> Option<<Self as Div<Self>>::Output>;
    fn checked_div_exact(self, rhs: Self) -> Option<<Self as Div<Self>>::Output>;
}
Expand description

Performs division without remainder.

Required Methods§

Source

fn div_exact(self, rhs: Self) -> Option<<Self as Div<Self>>::Output>

Integer division without remainder. Computes self / rhs, returning None if self % rhs != 0.

§Panics

Panics if rhs is zero, or — with overflow checks enabled — on MIN / -1 for signed types.

use const_num_traits::DivExact;

assert_eq!(DivExact::div_exact(64u8, 2), Some(32));
assert_eq!(DivExact::div_exact(65u8, 2), None);
Source

fn checked_div_exact(self, rhs: Self) -> Option<<Self as Div<Self>>::Output>

Checked integer division without remainder. Computes self / rhs, returning None if rhs == 0, self % rhs != 0, or the division overflowed (MIN / -1 on a signed type).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl DivExact for i8

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for i16

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for i32

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for i64

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for i128

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for isize

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for u8

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for u16

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for u32

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for u64

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for u128

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Source§

impl DivExact for usize

Source§

fn div_exact(self, rhs: Self) -> Option<Self>

Source§

fn checked_div_exact(self, rhs: Self) -> Option<Self>

Implementors§