safe_arith 0.1.0

Safe arithmetic on integers, which avoids overflow and division by zero.
Documentation
  • Coverage
  • 75%
    18 out of 24 items documented1 out of 17 items with examples
  • Size
  • Source code size: 12.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.11 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • sigp/safe_arith
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • macladson

safe_arith

CI Crates.io Documentation

Safe arithmetic on integers, avoiding overflow and division by zero.

Why not just use checked_* methods?

Rust's built-in checked_add, checked_mul, etc. return Option<T>, which requires you to manually handle None cases without context about what went wrong. This crate provides:

  1. Explicit errors: Returns Result<T, ArithError> with explicit Overflow and DivisionByZero variants
  2. Assignment operators: Methods like safe_add_assign that mutate in place
  3. Iterator support: safe_sum() method for safely summing iterators without overflow