#unique-identifier #identifier #uuid #sortable

no-std ulid

a Universally Unique Lexicographically Sortable Identifier implementation

20 releases (5 stable)

1.1.2 Feb 3, 2024
1.1.0 Sep 11, 2023
1.0.0 Aug 2, 2022
0.6.0 Jun 18, 2022
0.2.2 Jul 28, 2017

#19 in Algorithms

Download history 27040/week @ 2024-01-03 30152/week @ 2024-01-10 36384/week @ 2024-01-17 33920/week @ 2024-01-24 39190/week @ 2024-01-31 39757/week @ 2024-02-07 47648/week @ 2024-02-14 43972/week @ 2024-02-21 46841/week @ 2024-02-28 52322/week @ 2024-03-06 51533/week @ 2024-03-13 47876/week @ 2024-03-20 39640/week @ 2024-03-27 50250/week @ 2024-04-03 47440/week @ 2024-04-10 47159/week @ 2024-04-17

193,409 downloads per month
Used in 202 crates (108 directly)

MIT license

41KB
694 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.2MB
~34K SLoC