ulid-rs
July 16, 2026 ยท View on GitHub
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::generate();
// 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 ofstdandrand. Disable this flag for#[no_std]support.serde: Enables serialization and deserialization ofUlidtypes viaserde. ULIDs are serialized using their canonical 26-character representation as defined in the ULID standard. An optionalulid_as_u128module is provided, which enables serialization through anUlid's inneru128primitive type. See the documentation and serde docs for more information.uuid: Implements infallible conversions between ULIDs and UUIDs from theuuidcrate via thestd::convert::Fromtrait.
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)
Changelog
v3.0.0
- Rename
Ulid::gen()(previouslyUlid::new()) toUlid::generate()for better compatability with edition2024
v2.0.1
- Add support for
rand = "0.10" - Replaced
MonotonicError::OverflowwithOverflow. Generator results can now be properly overflowed usingOverflow::commit_overflow_random()orOverflow::commit_overflow_random().- To keep existing client behavior, drop the
Overflowvalue.generator.generate().map_err(|_| MyOverflowError)
- To keep existing client behavior, drop the
- Rename
Ulid::new()toUlid::new()for better compatability with edition2024 - Add
Ulid::max()andUlid::is_max() - Add
consttoUlid::array_to_str()(Thanks Hermholtz) - Removed deprecated
Ulid::to_str()