std-method
Unsigned next_multiple_of and checked_next_multiple_of
Round a payload length up to a multiple of its block size. The checked form rejects zero and overflow; the unchecked form can overflow or panic. Expected stdout (not executed): 24 Some(32) None Common mistake: Assuming rounding up always fits the integer type.
Formal Syntax & Structure
rust syntaxrust
n.next_multiple_of(d); n.checked_next_multiple_of(d)Working Example
Example Snippetrust
fn main() { println!("{}", 21u32.next_multiple_of(8)); println!("{:?} {:?}", 32u32.checked_next_multiple_of(8), u32::MAX.checked_next_multiple_of(8));}