18 releases (3 stable)
1.1.0 | Sep 11, 2023 |
---|---|
1.0.0 | Aug 2, 2022 |
0.6.0 | Jun 18, 2022 |
0.5.0 | Nov 4, 2021 |
0.2.2 | Jul 28, 2017 |
#17 in Algorithms
123,490 downloads per month
Used in 140 crates
(80 directly)
39KB
667 lines
ulid-rs
This is a Rust implementation of the ulid project which provides Universally Unique Lexicographically Sortable Identifiers.
Quickstart
use ulid::Ulid;
// Generate a ulid
let ulid = Ulid::new();
// Generate a string for a ulid
let s = ulid.to_string();
// Create from a String
let res = Ulid::from_string(&s);
assert_eq!(ulid, res.unwrap());
Crate Features
std
(default): Flag to toggle use ofstd
andrand
. Disable this flag for#[no_std]
support.serde
: Enables serialization and deserialization ofUlid
types viaserde
. ULIDs are serialized using their canonical 26-character representation as defined in the ULID standard. An optionalulid_as_u128
module is provided, which enables serialization through anUlid
's inneru128
primitive type. See the documentation and serde docs for more information.uuid
: Implements infallible conversions between ULIDs and UUIDs from theuuid
crate via thestd::convert::From
trait.
Benchmark
Benchmarks were run on my desktop (Win 10/WSL2 Ubuntu; Ryzen 7 5950x). Run them yourself with cargo bench
.
test bench_from_string ... bench: 13 ns/iter (+/- 0)
test bench_from_time ... bench: 13 ns/iter (+/- 0)
test bench_generator_generate ... bench: 29 ns/iter (+/- 0)
test bench_new ... bench: 31 ns/iter (+/- 1)
test bench_to_str ... bench: 7 ns/iter (+/- 0)
test bench_to_string ... bench: 19 ns/iter (+/- 0)
Dependencies
~0–1MB
~30K SLoC