#sortable #uuid #ulid

no-std ulid

a Universally Unique Lexicographically Sortable Identifier implementation

24 releases (9 stable)

1.2.1 Mar 17, 2025
1.1.4 Jan 9, 2025
1.1.3 Jul 13, 2024
1.1.2 Feb 3, 2024
0.2.2 Jul 28, 2017

#20 in Algorithms

Download history 32372/week @ 2024-12-22 37965/week @ 2024-12-29 90622/week @ 2025-01-05 98070/week @ 2025-01-12 91131/week @ 2025-01-19 99359/week @ 2025-01-26 117030/week @ 2025-02-02 113937/week @ 2025-02-09 92999/week @ 2025-02-16 98849/week @ 2025-02-23 106792/week @ 2025-03-02 117940/week @ 2025-03-09 123122/week @ 2025-03-16 94475/week @ 2025-03-23 81356/week @ 2025-03-30 98301/week @ 2025-04-06

404,060 downloads per month
Used in 397 crates (190 directly)

MIT license

43KB
721 lines

ulid-rs

Build Status Crates.io docs.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 of std and rand. Disable this flag for #[no_std] support.
  • serde: Enables serialization and deserialization of Ulid types via serde. ULIDs are serialized using their canonical 26-character representation as defined in the ULID standard. An optional ulid_as_u128 module is provided, which enables serialization through an Ulid's inner u128 primitive type. See the documentation and serde docs for more information.
  • uuid: Implements infallible conversions between ULIDs and UUIDs from the uuid crate via the std::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–1.4MB
~29K SLoC