std-method

Integer checked_mul

Check a size calculation before allocating storage. This only checks arithmetic, not whether allocation succeeds. Expected stdout (not executed): Some(200) None Common mistake: Treating a representable size as proof that enough memory exists.

Formal Syntax & Structure

rust syntaxrust
x.checked_mul(y) -> Option<Self>

Working Example

Example Snippetrust
fn main() {    let rows = 20u8;    println!("{:?}", rows.checked_mul(10));    println!("{:?}", rows.checked_mul(20));}
Rust Reference