https://github.com/kazk/xid-rs
Globally unique sortable id generator. A Rust port of https://github.com/rs/xid.
https://github.com/kazk/xid-rs
id rust
Last synced: 2 months ago
JSON representation
Globally unique sortable id generator. A Rust port of https://github.com/rs/xid.
- Host: GitHub
- URL: https://github.com/kazk/xid-rs
- Owner: kazk
- License: mit
- Created: 2020-12-12T10:13:13.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T09:21:39.000Z (about 1 year ago)
- Last Synced: 2025-06-17T03:49:40.618Z (4 months ago)
- Topics: id, rust
- Language: Rust
- Homepage: https://docs.rs/xid
- Size: 31.3 KB
- Stars: 37
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# xid
[](https://github.com/kazk/xid-rs/actions?query=workflow%3ACI)
[](https://crates.io/crates/xid)
[](https://docs.rs/xid/)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][object-id].
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 valueThe 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
```rust
println!("{}", xid::new()); //=> bva9lbqn1bt68k8mj62g
```## Examples
- [`cargo run --example gen`](./examples/gen.rs): Generate xid
[`xid`]: https://github.com/rs/xid
[object-id]: https://docs.mongodb.org/manual/reference/object-id/