Skip to main content

DivExact

Trait DivExact 

Source
pub trait DivExact: Sized {
    type Output;

    // Required methods
    fn div_exact(self, rhs: Self) -> Option<Self::Output>;
    fn checked_div_exact(self, rhs: Self) -> Option<Self::Output>;
}
Expand description

Performs division without remainder.

Required Associated Types§

Source

type Output

The quotient type (Self for the primitive impls).

Required Methods§

Source

fn div_exact(self, rhs: Self) -> Option<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::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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = 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§

type Output = usize

Source§

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

Source§

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

Implementors§