https://github.com/hanaasagi/ticket
:ticket: Unique ID Generator
https://github.com/hanaasagi/ticket
global-id id uid
Last synced: 8 months ago
JSON representation
:ticket: Unique ID Generator
- Host: GitHub
- URL: https://github.com/hanaasagi/ticket
- Owner: Hanaasagi
- License: bsd-3-clause
- Created: 2018-09-22T00:59:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-10T15:55:38.000Z (about 3 years ago)
- Last Synced: 2025-10-06T18:58:49.962Z (9 months ago)
- Topics: global-id, id, uid
- Language: Rust
- Homepage: https://crates.io/crates/ticket
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ticket
Unique-ID-Generator inspired by [rs/xid](https://github.com/rs/xid).
[![ticket on GitHub Action][action-image]][action]
[![ticket on crates.io][cratesio-image]][cratesio]
[![ticket on docs.rs][docsrs-image]][docsrs]
[action-image]: https://github.com/Hanaasagi/ticket/actions/workflows/ci.yaml/badge.svg
[action]: https://github.com/Hanaasagi/ticket/actions/workflows/ci.yaml
[cratesio-image]: https://img.shields.io/crates/v/ticket.svg
[cratesio]: https://crates.io/crates/ticket
[docsrs-image]: https://docs.rs/ticket/badge.svg
[docsrs]: https://docs.rs/ticket
```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
) (
--- ---
9 _____ ___ ___ _ _____ _____ 7
6 |_ _|_ _/ __| |/ / __|_ _| 1
3 | | | | (__| ' <| _| | | 6
8 |_| |___\___|_|\_\___| |_| 5
0 2
--- ---
)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _(
```
### About Ticket
The ID generated from Ticket only occupies 12 bytes.
- 4-byte from unix timestamp,
- 3-byte from machine id,
- 2-byte from current process id, and
- 3-byte counter which starting with a random value.
### Usage
Put this in your `Cargo.toml`:
```Toml
[dependencies]
ticket = { git = "https://github.com/Hanaasagi/ticket" }
```
Use it like following
```Rust
extern crate ticket;
use ticket::{Ticketing, encode, decode};
fn main() {
// create a `Ticketing` to generate ticket number.
let id = Ticketing::new().gen();
// using base32 encoding.
println!("{}", id); // "bekcs9rrtf0263qgv5r0"
// as 12 bytes array.
println!("{:?}", id.as_bytes()); // [91, 168, 206, 39, 123, 235, 192, 35, 15, 80, 249, 118]
// encode and dedode
assert_eq!(decode(&encode(id)), id);
}
```
### License
[BSD 3-Clause License](https://github.com/Hanaasagi/ticket/blob/master/LICENSE) Copyright (c) 2018, Hanaasagi