ticket

Crates.ioticket
lib.rsticket
version0.2.0
sourcesrc
created_at2018-10-06 14:15:20.296625
updated_at2023-04-10 15:56:08.634724
descriptiongenerate unique id which occupies 12 bytes.
homepage
repositoryhttps://github.com/Hanaasagi/ticket
max_upload_size
id88377
size14,069
(Hanaasagi)

documentation

README

Ticket

Unique-ID-Generator inspired by rs/xid.

ticket on GitHub Action ticket on crates.io ticket on docs.rs

   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  )                                (
---                                  ---
  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:

[dependencies]
ticket = { git = "https://github.com/Hanaasagi/ticket" }

Use it like following

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 Copyright (c) 2018, Hanaasagi

Commit count: 35

cargo fmt