Skip to main content

NextMultipleOf

Trait NextMultipleOf 

Source
pub trait NextMultipleOf:
    Sized
    + Add<Self>
    + Rem<Self> {
    // Required methods
    fn next_multiple_of(self, rhs: Self) -> <Self as Add<Self>>::Output;
    fn checked_next_multiple_of(
        self,
        rhs: Self,
    ) -> Option<<Self as Add<Self>>::Output>;
}
Expand description

Rounds up to the nearest multiple of a value.

Required Methods§

Source

fn next_multiple_of(self, rhs: Self) -> <Self as Add<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 as Add<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§

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§

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§

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§

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§

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§

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§

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§

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§

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§

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§

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§

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

Source§

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

Implementors§