Crates.io | dactyl |
lib.rs | dactyl |
version | |
source | src |
created_at | 2021-02-20 05:54:06.740289 |
updated_at | 2024-12-08 03:56:14.180474 |
description | A small library to quickly stringify integers with basic formatting. |
homepage | |
repository | https://github.com/Blobfolio/dactyl |
max_upload_size | |
id | 357856 |
Cargo.toml error: | TOML parse error at line 27, column 1 | 27 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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 u8
s.
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 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 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
Add dactyl
to your dependencies
in Cargo.toml
, like:
[dependencies]
dactyl = "0.9.*"