Crates.io | lexicoid |
lib.rs | lexicoid |
version | 0.1.0 |
source | src |
created_at | 2023-01-21 19:13:33.247371 |
updated_at | 2023-01-21 19:13:33.247371 |
description | Short & stable IDs based on timestamps |
homepage | |
repository | https://github.com/lmammino/lexicoid |
max_upload_size | |
id | 764550 |
size | 12,933 |
Short & stable IDs based on timestamps.
Heavily inspired by Short, friendly base32 slugs from timestamps by @brandur.
Install with cargo by updating your Cargo.toml
:
[dependencies]
lexicoid = "*"
or with cargo-add
you can run:
cargo add lexicoid
use lexicoid::*;
// generates a lexicoid for the current timestamp
println!("{}", lexicoid_now()); // gj7x3vc
// generates a lexicoid for a given unix timestamp (as u64)
println!("{}", lexicoid(1654401676)); // gei4p52
Whenever you need simple and short ids that are lexicographically sorted based on the generation timestamp.
Examples:
Warning: since the resolution of the timestamps is per second, if you try to generate multiple ids in the same second, they will all be equal. This is not directly suitable for high frequency ID generation. But, if you need to adapt this approach to high frequency ID generation, you can always append the current number of milliseconds (or nanoseconds) to the generated ID.
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
Licensed under MIT License. © Luciano Mammino.