Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allevo/hyperid-rs
Superfast id generator
https://github.com/allevo/hyperid-rs
Last synced: 14 days ago
JSON representation
Superfast id generator
- Host: GitHub
- URL: https://github.com/allevo/hyperid-rs
- Owner: allevo
- License: mit
- Created: 2021-03-28T20:21:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-14T20:47:27.000Z (over 3 years ago)
- Last Synced: 2024-10-10T20:20:36.968Z (about 1 month ago)
- Language: Rust
- Size: 37.1 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hyperid-rs [![Rust](https://github.com/allevo/hyperid-rs/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/allevo/hyperid-rs/actions/workflows/rust.yml)
Superfast id generatorThis is a porting of the amazing hyperid project written in [javascript](https://github.com/mcollina/hyperid).
## Install
Add the dependency to your `Cargo.toml`:
```toml
[dependencies]
hyperid = "2"
```## Usage
```rust
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"
}
```## Benchmark
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)
...
```## Features
This crate has a feature `url_safe` that adds `to_url_safe` and `from_url_safe` methods.
## Prepare for release
```sh
cargo release -vv --skip-publish
# wait for CI
git checkout
cargo publish
```## License
See [LICENSE](./LICENSE) file