8个稳定版本
2.3.1 | 2021年8月14日 |
---|---|
2.2.0 | 2021年8月14日 |
2.1.1 | 2021年4月4日 |
2.0.1-alpha.3 |
|
1.1.1 | 2021年3月28日 |
#1972 in 算法
12KB
176 行
hyperid-rs 
超快速ID生成器
这是对用javascript编写的惊人hyperid项目的移植。
安装
将依赖项添加到您的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"
}
基准测试
这个crate旨在提供快速的ID生成器。与uuid crates相比,在我的计算机上
$ cargo bench
...
test hyperid ... bench: 9 ns/iter (+/- 1)
test uuid ... bench: 1,657 ns/iter (+/- 148)
...
功能
此crate有一个功能url_safe
,它添加了to_url_safe
和from_url_safe
方法。
准备发布
cargo release -vv --skip-publish <version>
# wait for CI
git checkout <tag>
cargo publish
许可证
请参阅LICENSE文件
依赖项
~285–510KB