#id-generator #unique-id #unique-identifier #id #process-id #object-id #sortable

xid

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

8 releases (stable)

new 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

#164 in Database interfaces

Download history 1389/week @ 2024-01-06 1618/week @ 2024-01-13 1876/week @ 2024-01-20 1547/week @ 2024-01-27 2316/week @ 2024-02-03 1736/week @ 2024-02-10 2048/week @ 2024-02-17 1946/week @ 2024-02-24 2557/week @ 2024-03-02 2434/week @ 2024-03-09 1450/week @ 2024-03-16 2054/week @ 2024-03-23 1789/week @ 2024-03-30 1039/week @ 2024-04-06 1084/week @ 2024-04-13 1630/week @ 2024-04-20

5,730 downloads per month
Used in 16 crates (9 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.7–8.5MB
~67K SLoC