std-method

Unsigned div_ceil

Find the number of pages needed for n items at d items per page, rounding up. A zero divisor panics. Expected stdout (not executed): 3 2 Common mistake: Using (n + d - 1) / d without considering overflow.

Formal Syntax & Structure

rust syntaxrust
n.div_ceil(d) -> Self

Working Example

Example Snippetrust
fn main() {    let items = 23u32;    println!("{} {}", items.div_ceil(10), 20u32.div_ceil(10));}
Rust Reference