safe_arith

Crates.iosafe_arith
lib.rssafe_arith
version0.1.0
created_at2025-10-12 10:16:02.931516+00
updated_at2025-10-12 10:16:02.931516+00
descriptionSafe arithmetic on integers, which avoids overflow and division by zero.
homepage
repositoryhttps://github.com/sigp/safe_arith
max_upload_size
id1879139
size12,734
crates-io (github:sigp:crates-io)

documentation

https://docs.rs/safe_arith

README

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
Commit count: 0

cargo fmt