Skip to main content

Crate use_integer

Crate use_integer 

Source
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.

Rust 1.95.0+ Edition 2024 Integer helpers License MIT or Apache-2.0

§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 helpers
IntegerSign, classify_sign, is_even, and is_odd keep branching on sign or parity explicit.
Checked divisibility
is_divisible_by reports IntegerError::DivisionByZero instead of leaving divisor validation to every caller.
Common-divisor helpers
gcd, lcm, and are_coprime provide small exact helpers for normalization and scheduling-style logic.
Helper groupPrimary itemsBest fit
Sign and parityIntegerSign, classify_sign, is_even, is_oddBranching on signed integer shape without ad hoc match logic
Divisibilityis_divisible_by, IntegerErrorUser-supplied divisors or explicit validation paths
Common divisorsgcd, lcm, are_coprimeNormalization, 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.

ScenarioUse use-integer directly?Why
You only need parity, sign, or divisibility helpersYesThe crate stays smaller than the facade and avoids unrelated numeric modules
You want exact gcd/lcm helpers over signed i128 valuesYesThe API already handles sign normalization and explicit error cases
You also need rational, real, probability, or geometry APIsUsually nouse-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;

Modules§

error
integer
prelude
Common ergonomic imports for use-integer.