Skip to content

sigp/safe_arith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages