Crates.io | hyperid |
lib.rs | hyperid |
version | 2.3.1 |
source | src |
created_at | 2021-03-28 21:11:26.56497 |
updated_at | 2021-08-14 20:48:43.049604 |
description | Superfast id generator |
homepage | |
repository | https://github.com/allevo/hyperid-rs |
max_upload_size | |
id | 374836 |
size | 16,624 |
Superfast id generator
This is a porting of the amazing hyperid project written in javascript.
Add the dependency to your Cargo.toml
:
[dependencies]
hyperid = "2"
use hyperid::HyperId;
fn main() {
let mut hyperid = HyperId::default();
// `generate` method returns a new id every time
let id1 = hyperid.generate();
let id2 = hyperid.generate();
assert_ne!(id1, id2);
// `get` method returns the last generated id
let id3 = hyperid.get();
assert_eq!(id2, id3);
// Only if `url_safe` feature is enabled
println!("{}", id1.to_url_safe()); // prints "3ZAYYJilG7vHTqiUuaQdFg.0"
}
This crate borns for providing a fast id generator. Comparing with uuid crates, on my computer:
$ cargo bench
...
test hyperid ... bench: 9 ns/iter (+/- 1)
test uuid ... bench: 1,657 ns/iter (+/- 148)
...
This crate has a feature url_safe
that adds to_url_safe
and from_url_safe
methods.
cargo release -vv --skip-publish <version>
# wait for CI
git checkout <tag>
cargo publish
See LICENSE file