#id-generator #unique-id #unique-identifier #id #object-id #process-id #mongo-db

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

#422 in Database interfaces

Download history 1515/week @ 2024-09-21 1355/week @ 2024-09-28 1682/week @ 2024-10-05 1650/week @ 2024-10-12 1599/week @ 2024-10-19 1308/week @ 2024-10-26 1650/week @ 2024-11-02 1766/week @ 2024-11-09 1387/week @ 2024-11-16 1410/week @ 2024-11-23 1382/week @ 2024-11-30 1437/week @ 2024-12-07 1336/week @ 2024-12-14 1047/week @ 2024-12-21 560/week @ 2024-12-28 977/week @ 2025-01-04

4,247 downloads per month
Used in 17 crates (10 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.6–7.5MB
~58K SLoC