Expand description
§use-integer
Small integer classifications and common-divisor helpers for `RustUse`.
Parity, sign classification, divisibility checks, and explicit gcd/lcm helpers without a broader numeric framework.
§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.
Classification helpersIntegerSign, classify_sign, is_even, and is_odd keep branching on sign or parity explicit.
|
Checked divisibilityis_divisible_by reports IntegerError::DivisionByZero instead of leaving divisor validation to every caller.
|
Common-divisor helpersgcd, lcm, and are_coprime provide small exact helpers for normalization and scheduling-style logic.
|
| 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));
§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.
Integer helpers for RustUse.
Re-exports§
pub use error::IntegerError;pub use integer::IntegerSign;pub use integer::are_coprime;pub use integer::classify_sign;pub use integer::gcd;pub use integer::is_divisible_by;pub use integer::is_even;pub use integer::is_odd;pub use integer::lcm;