safe_arith 0.1.0

Safe arithmetic on integers, which avoids overflow and division by zero.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# safe_arith

[![CI](https://github.com/sigp/safe_arith/workflows/test-suite/badge.svg)](https://github.com/sigp/safe_arith/actions)
[![Crates.io](https://img.shields.io/crates/v/safe_arith.svg)](https://crates.io/crates/safe_arith)
[![Documentation](https://docs.rs/safe_arith/badge.svg)](https://docs.rs/safe_arith)

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