safe_math_legacy 1.1.3

Deprecated! Math without overflow, creates an enum and a macro to help mitigate any overflow while multiplying and adding
Documentation
  • Coverage
  • 40%
    2 out of 5 items documented0 out of 2 items with examples
  • Size
  • Source code size: 1.27 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 309.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • XDDudeGuy/safe_math
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • XDDudeGuy

DEPRECATED! NEW VERSION HERE

Safe Math

Math without overflow!

Adds a macro and an enum safe_math!() and Operation

src/safe_math.rs

Operation:

pub enum Operation {
  ...
}

Has two variants Add and Multiply with no fields, used in the safe_math!() macro to determine whether you are adding or multiplying the inputted numbers

safe_math!():

#[macro_export]
macro_rules! safe_math {
  ($in_x:expr, $in_y:expr, $operation:expr)
}

This takes three expression arguments, the first two being the numbers you wish to use and the third being the operation you wish to apply to the numbers whether that be addition or multiplication. The first two expressions should be below the unsigned 64 bit integer limit and the third should be a variant of the Operation enum. Most errors will just return the larger of the two number input variables in the Err() variant of the Result enum