#unique-id-generator #unique-identifier

xid

Globally unique sortable id generator. A Rust port of https://github.com/rs/xid.

8 releases (stable)

1.1.1 Apr 23, 2024
1.0.3 Oct 14, 2022
1.0.2 Jul 5, 2022
1.0.1 Jun 24, 2022
0.1.1 Dec 13, 2020

#767 in Text processing

Download history 2224/week @ 2025-10-14 1811/week @ 2025-10-21 1820/week @ 2025-10-28 2025/week @ 2025-11-04 1960/week @ 2025-11-11 1937/week @ 2025-11-18 1987/week @ 2025-11-25 1655/week @ 2025-12-02 1852/week @ 2025-12-09 1897/week @ 2025-12-16 1313/week @ 2025-12-23 1813/week @ 2025-12-30 1356/week @ 2026-01-06 2404/week @ 2026-01-13 2081/week @ 2026-01-20 2340/week @ 2026-01-27

8,431 downloads per month
Used in 34 crates (17 directly)

MIT license

22KB
418 lines

xid

CI Crates.io API reference

Globally unique sortable id generator. A Rust port of https://github.com/rs/xid.

The binary representation is compatible with the Mongo DB 12-byte ObjectId. The value consists of:

  • a 4-byte timestamp value in seconds since the Unix epoch
  • a 3-byte value based on the machine identifier
  • a 2-byte value based on the process id
  • a 3-byte incrementing counter, initialized to a random value

The string representation is 20 bytes, using a base32 hex variant with characters [0-9a-v] to retain the sortable property of the id.

See the original xid project for more details.

Usage

println!("{}", xid::new()); //=> bva9lbqn1bt68k8mj62g

Examples

Dependencies

~0.5–3MB
~55K SLoC