thousands
A Rust crate that adds digit separators to numbers via the Separable trait, configurable by separator and grouping policy.
Repository Health
Technical Analysis
thousands is a small, focused Rust crate for formatting numbers with digit separators. It provides the Separable trait, whose methods such as separate_with_commas, separate_with_spaces, separate_with_dots, and separate_with_underscores turn values like 12345 into human-readable strings like 12,345.
For cases where the default three-digit grouping is not enough, a SeparatorPolicy lets you control the separator character, the group sizes (for example the [3, 2] grouping used in the Indian numbering system), and which digit set counts as a digit, making the crate usable across locales and file formats.
What You Get
- The
Separabletrait implemented for Rust’s integer and floating-point types - Convenience methods:
separate_with_commas,separate_with_spaces,separate_with_dots,separate_with_underscores - A configurable
SeparatorPolicyfor custom separators and group sizes - Predefined digit sets (e.g.
digits::ASCII_DECIMAL) for policy configuration - A tiny, dependency-free API that preserves signs and fractional parts
Common Use Cases
- Displaying large integers or currency amounts with comma separators in a UI or report
- Formatting numbers with locale-specific grouping such as spaces or the Indian [3,2] system
- Producing human-readable numeric output in CLI tools and logs
Under The Hood
Architecture — The crate is split into small modules: traits.rs defines the Separable trait and its convenience methods, policies.rs holds SeparatorPolicy and the built-in policies, digits.rs defines digit sets, display.rs implements the actual separator insertion, and helpers.rs and lib.rs tie them together. Formatting works by walking a number’s digits and inserting the configured separator at the group boundaries defined by the policy.
Tech Stack — Pure Rust with no runtime dependencies. It targets Rust 1.22+ and relies only on the standard library, making it lightweight to add to any project.
Code Quality — The code is compact (~18 KB of Rust across six files) and easy to audit, with unit tests in display.rs and helpers.rs covering the grouping logic and sign/fraction handling. The project is stable and mature but has seen no recent activity.
API Design — The API is intentionally minimal and ergonomic: importing Separable makes the separate_with_* methods available directly on numeric values, so the common case is a single method call. The SeparatorPolicy struct exposes the full configuration for advanced grouping without complicating the simple path.