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 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:
NiceU8NiceU16NiceU32NiceU64(also coversusize)NiceFloatNiceElapsed(for durations)NicePercent(for floats representing percentages)
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 NiceU16;
assert_eq!;
assert_eq!;
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 integerHashSet/HashMapcollectionstraits::BytesToSigned: signed integer parsing from byte slicestraits::BytesToUnsigned: unsigned integer parsing from byte slicestraits::HexToSigned: signed integer parsing from hextraits::HexToUnsigned: unsigned integer parsing from hex
Installation
Add dactyl to your dependencies in Cargo.toml, like:
[dependencies]
dactyl = "0.8.*"