#unsigned-integer #integer #formatting

dactyl

A small library to quickly stringify integers with basic formatting

48 releases

Uses new Rust 2024

0.13.2 Dec 11, 2025
0.13.1 Aug 12, 2025
0.13.0 Jun 26, 2025
0.10.0 Feb 25, 2025
0.1.7 Mar 17, 2021

#46 in Value formatting

Download history 310/week @ 2025-11-06 257/week @ 2025-11-13 210/week @ 2025-11-20 478/week @ 2025-11-27 232/week @ 2025-12-04 283/week @ 2025-12-11 220/week @ 2025-12-18 215/week @ 2025-12-25 375/week @ 2026-01-01 178/week @ 2026-01-08 114/week @ 2026-01-15 276/week @ 2026-01-22 157/week @ 2026-01-29 341/week @ 2026-02-05 270/week @ 2026-02-12 282/week @ 2026-02-19

1,069 downloads per month
Used in 15 crates (4 directly)

WTFPL license

185KB
4K SLoC

Dactyl

docs.rs changelog
crates.io ci deps.rs
license contributions welcome

This crate provides a fast interface to "stringify" unsigned integers, formatted with commas at each thousand. It prioritizes speed and simplicity over configurability.

If your application just wants to quickly turn 1010 into "1,010", Dactyl is a great choice. If your application requires locale awareness or other options, something like num-format would probably make more sense.

Similar to itoa, Dactyl writes ASCII conversions to a temporary buffer, but does so using fixed arrays sized for each type's maximum value, minimizing the allocation overhead for, say, tiny little u8s.

Each type has its own struct, each of which works exactly the same way:

  • NiceU8
  • NiceU16
  • NiceU32
  • NiceU64 (also covers usize)
  • NiceFloat
  • NiceClock (for durations)
  • NiceElapsed (also for durations)
  • NicePercent (for percentage-like floats)

The intended use case is to simply call the appropriate from() for the type, then use either the as_str() or as_bytes() struct methods to retrieve the output in the desired format. Each struct also implements traits like Display, AsRef<str>, AsRef<[u8]>, etc., if you prefer those.

use dactyl::NiceU16;

assert_eq!(NiceU16::from(11234_u16).as_str(), "11,234");
assert_eq!(NiceU16::from(11234_u16).as_bytes(), b"11,234");

But the niceness doesn't stop there. Dactyl provides several other structs, methods, and traits to performantly work with integers, such as:

  • NoHash: a passthrough hasher for integer HashSet/HashMap collections
  • traits::BytesToSigned: signed integer parsing from byte slices
  • traits::BytesToUnsigned: unsigned integer parsing from byte slices
  • traits::HexToSigned: signed integer parsing from hex
  • traits::HexToUnsigned: unsigned integer parsing from hex

Installation

Add dactyl to your dependencies in Cargo.toml, like:

[dependencies]
dactyl = "0.13.*"

No runtime deps