Skip to main content

NextMultipleOf

Trait NextMultipleOf 

Source
pub trait NextMultipleOf: Sized {
    type Output;

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

Rounds up to the nearest multiple of a value.

Required Associated Types§

Source

type Output

The result type (Self for the primitive impls).

Required Methods§

Source

fn next_multiple_of(self, rhs: Self) -> Self::Output

Calculates the smallest value greater than or equal to self that is a multiple of rhs (for negative rhs on signed types: the closest to negative infinity).

§Panics

Panics if rhs is zero, or — with overflow checks enabled — if the result overflows.

use const_num_traits::NextMultipleOf;

assert_eq!(NextMultipleOf::next_multiple_of(16u8, 8), 16);
assert_eq!(NextMultipleOf::next_multiple_of(23u8, 8), 24);
assert_eq!(NextMultipleOf::next_multiple_of(-16i8, -5), -20);
Source

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

Calculates the smallest value greater than or equal to self that is a multiple of rhs, returning None if rhs is zero or the operation would result in overflow.

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

Source§

type Output = i8

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for i16

Source§

type Output = i16

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for i32

Source§

type Output = i32

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for i64

Source§

type Output = i64

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for i128

Source§

type Output = i128

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for isize

Source§

type Output = isize

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for u8

Source§

type Output = u8

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for u16

Source§

type Output = u16

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for u32

Source§

type Output = u32

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for u64

Source§

type Output = u64

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for u128

Source§

type Output = u128

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Source§

impl NextMultipleOf for usize

Source§

type Output = usize

Source§

fn next_multiple_of(self, rhs: Self) -> Self

Source§

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

Implementors§