use-integer 0.0.6

Utility-first integer helpers for RustUse
Documentation

use-integer

Install

[dependencies]
use-integer = "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 use_integer::{IntegerSign, classify_sign, is_even, is_odd};

assert_eq!(classify_sign(-7), IntegerSign::Negative);
assert!(is_even(12));
assert!(is_odd(7));

Check divisibility and common divisors

use use_integer::{are_coprime, gcd, is_divisible_by, lcm};

assert!(is_divisible_by(84, 7)?);
assert_eq!(gcd(-54, 24), 6);
assert_eq!(lcm(-6, 15)?, 30);
assert!(are_coprime(35, 64));

# Ok::<(), use_integer::IntegerError>(())

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.