unwrap-overflow-ops 0.1.0

arithmetic operations that always panic on overflow
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented13 out of 16 items with examples
  • Size
  • Source code size: 26.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 831.67 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Techcable/unwrap-overflow-ops.rust
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Techcable

unwrap-overflow-ops

Crates.io Version docs.rs

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);

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.