#ulid #uuid #sortable #identifier

ulid

a Universally Unique Lexicographically Sortable Identifier implementation

16 releases (1 stable)

1.0.0 Aug 2, 2022
0.6.0 Jun 18, 2022
0.5.0 Nov 4, 2021
0.4.1 Sep 29, 2020
0.2.2 Jul 28, 2017

#33 in Algorithms

Download history 2282/week @ 2022-04-25 2616/week @ 2022-05-02 2619/week @ 2022-05-09 5177/week @ 2022-05-16 2873/week @ 2022-05-23 3309/week @ 2022-05-30 3828/week @ 2022-06-06 3363/week @ 2022-06-13 3354/week @ 2022-06-20 3902/week @ 2022-06-27 3954/week @ 2022-07-04 4508/week @ 2022-07-11 4537/week @ 2022-07-18 4958/week @ 2022-07-25 5107/week @ 2022-08-01 4869/week @ 2022-08-08

19,649 downloads per month
Used in 21 crates (17 directly)

MIT license

36KB
602 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–280KB