Expand description
Dactyl
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 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 u8
s.
Each type has its own struct, each of which works exactly the same way:
(Note: support for usize
values is folded into NiceU64
.)
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 Deref
, 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");
This crate also contains two “in development” structs — NicePercent
and NiceElapsed
— that can be useful for formatting percentages and durations, however their implementations are subject to change and they might eventually be split off into their own crates.
Modules
Dactyl: Traits
Structs
Greater Than Zero
This is a very simple struct for efficiently converting a given number of
seconds (u32
) into a nice, human-readable Oxford-joined byte string, like
3 hours, 2 minutes, and 1 second
.
NicePercent
provides a quick way to convert an f32
or f64
into a
formatted byte string for e.g. printing.
NiceU8
provides a quick way to convert a u8
into a formatted byte
string for e.g. printing.
NiceU16
provides a quick way to convert a u16
into a formatted byte
string for e.g. printing. Commas are added for every thousand.
NiceU32
provides a quick way to convert a u32
into a formatted byte
string for e.g. printing. Commas are added for every thousand.
NiceU64
provides a quick way to convert a u64
into a formatted byte
string for e.g. printing. Commas are added for every thousand.
Functions
Floored Div/Mod.
Floored Div/Mod.
Floored Div/Mod.
Floored Div/Mod.
Floored Div/Mod.
Floored Div/Mod.
Floored Division.
Floored Division.
Floored Division.
Floored Division.
Floored Division.
Floored Division.
Integer to Float Division.
Write Time.