Crate unwrap_overflow_ops

Source
Expand description

Arithmetic operations that always panic overflow, providing a polyfill for the [unwrap_overflow_ops feature].

To avoid conflicts with the standard library, methods are prefixed with unwrap_ instead of strict_. For example i32::strict_add becomes UnwrapOverflowOps::unwrap_add.

Methods are available through the UnwrapOverflowOps extension trait. Some methods are only supported for signed/unsigned integers, and require UnwrapOverflowOpsSigned or UnwrapOverflowOpsUnsigned.

Import the entire crate to use all three traits: use strict_overflow_ops::*;

§Example

use unwrap_overflow_ops::*;

assert_eq!(0i32.unwrap_add(5), 5);
assert_eq!(7u32.unwrap_add_signed(-3), 4);
assert_eq!(-7i32.unwrap_neg(), 7);

Traits§

UnwrapOverflowOps
An extension trait for arithmetic operations that are guaranteed to panic on overflow.
UnwrapOverflowOpsSigned
An extension trait for signed arithmetic operations that are guaranteed to panic on overflow.
UnwrapOverflowOpsUnsigned
An extension trait for unsigned arithmetic operations that are guaranteed to panic on overflow.