use-integer
Install
[]
= "0.0.1"
Foundation
use-integer provides a deliberately small integer helper surface. The crate covers sign classification, parity checks, runtime divisibility validation, and non-negative gcd/lcm helpers for signed i128 inputs. Operations that need a non-zero divisor or that would overflow while forming an lcm return IntegerError explicitly instead of silently panicking or widening the API surface.
| Helper group | Primary items | Best fit |
|---|---|---|
| Sign and parity | IntegerSign, classify_sign, is_even, is_odd |
Branching on signed integer shape without ad hoc match logic |
| Divisibility | is_divisible_by, IntegerError |
User-supplied divisors or explicit validation paths |
| Common divisors | gcd, lcm, are_coprime |
Normalization, factor checks, and least-common-multiple workflows |
When to use directly
Choose use-integer directly when integer helpers are the only surface you need and you want to keep that concern separate from broader numeric or algebraic APIs.
| Scenario | Use use-integer directly? |
Why |
|---|---|---|
| You only need parity, sign, or divisibility helpers | Yes | The crate stays smaller than the facade and avoids unrelated numeric modules |
You want exact gcd/lcm helpers over signed i128 values |
Yes | The API already handles sign normalization and explicit error cases |
| You also need rational, real, probability, or geometry APIs | Usually no | use-math can unify imports behind features |
Scope
- The current surface is intentionally small and concrete.
- Integer helpers stay function-oriented instead of introducing wrapper types with no extra invariants.
- Broader numeric abstractions belong in
use-number, while rational or algebraic APIs belong in their own focused crates.
Examples
Classify sign and parity
use ;
assert_eq!;
assert!;
assert!;
Check divisibility and common divisors
use ;
assert!;
assert_eq!;
assert_eq!;
assert!;
# Ok::
Status
use-integer is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent numeric crates are built out around it.