Is there a canonical way to explicitly check for integer overflow in Rust? I Googled around but couldn't find the answer.
Something like:
match add_or_overflow(x, y) {
None => println!("overflow!"),
Some(z) => println!("{} + {} = {}", x, y, z),
}
Or:
let x = OverflowChecked<i32>(_x);
let y = OverflowChecked<i32>(_y);
match x + y {
OverflowChecked::Overflow => println!("overflow!"),
OverflowChecked::Value(z) => println!("{} + {} = {}", x, y, z),
}
I could write this manually since Rust guarantees wrapping semantics, but I was just checking that there isn't some standard way to do this.