Crates.io | ticket |
lib.rs | ticket |
version | 0.2.0 |
source | src |
created_at | 2018-10-06 14:15:20.296625 |
updated_at | 2023-04-10 15:56:08.634724 |
description | generate unique id which occupies 12 bytes. |
homepage | |
repository | https://github.com/Hanaasagi/ticket |
max_upload_size | |
id | 88377 |
size | 14,069 |
Unique-ID-Generator inspired by rs/xid.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
) (
--- ---
9 _____ ___ ___ _ _____ _____ 7
6 |_ _|_ _/ __| |/ / __|_ _| 1
3 | | | | (__| ' <| _| | | 6
8 |_| |___\___|_|\_\___| |_| 5
0 2
--- ---
)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _(
The ID generated from Ticket only occupies 12 bytes.
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);
}
BSD 3-Clause License Copyright (c) 2018, Hanaasagi