Skip to main content

Module bounded

Module bounded 

Source
Expand description

Drop-in integer operations, and a refinement-typed integer.

The safe_* functions are the total-function route to overflow: each returns an Option, and crate::prove carries the proof that the None case is exactly the overflow case.

Bounded is the type-level route: a value known at compile time to lie in [MIN, MAX]. The constructors are the only way in, so the invariant cannot be broken by construction, and crate::prove::bounded_sub_is_total proves that Bounded::sub accepts exactly the in-range cases.

Structs§

Bounded
A value known at compile time to lie in [MIN, MAX].

Functions§

safe_add
a + b, or None on overflow.
safe_div
a / b, or None when b == 0. Division is defined for every nonzero divisor, so the only failure mode is the one made explicit here.
safe_mul
a * b, or None on overflow.
safe_rem
a % b, or None when b == 0.
safe_sub
a - b, or None on underflow.