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§
Required Methods§
Sourcefn next_multiple_of(self, rhs: Self) -> Self::Output
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);Sourcefn checked_next_multiple_of(self, rhs: Self) -> Option<Self::Output>
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".