#mongodb #machine #mongo-db

xid

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

6 releases (stable)

1.0.3 Oct 14, 2022
1.0.2 Jul 5, 2022
1.0.1 Jun 24, 2022
1.0.0 Feb 16, 2021
0.1.1 Dec 13, 2020

#718 in Database interfaces

Download history 1191/week @ 2023-08-12 1046/week @ 2023-08-19 2295/week @ 2023-08-26 1048/week @ 2023-09-02 1134/week @ 2023-09-09 1074/week @ 2023-09-16 1144/week @ 2023-09-23 1703/week @ 2023-09-30 1552/week @ 2023-10-07 1001/week @ 2023-10-14 948/week @ 2023-10-21 1682/week @ 2023-10-28 2101/week @ 2023-11-04 1413/week @ 2023-11-11 973/week @ 2023-11-18 1194/week @ 2023-11-25

5,804 downloads per month
Used in 11 crates (7 directly)

MIT license

20KB
373 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–1.5MB
~28K SLoC