8 stable releases

2.3.1 Aug 14, 2021
2.2.0 Aug 14, 2021
2.1.1 Apr 4, 2021
2.0.1-alpha.3 Mar 31, 2021
1.1.1 Mar 28, 2021

#260 in Algorithms

Download history 3/week @ 2022-01-23 3/week @ 2022-01-30 3/week @ 2022-02-06 2/week @ 2022-02-13 16/week @ 2022-02-20 4/week @ 2022-02-27 3/week @ 2022-03-06 53/week @ 2022-03-13 42/week @ 2022-03-20 3/week @ 2022-03-27 3/week @ 2022-04-03 2/week @ 2022-04-10 3/week @ 2022-04-17 24/week @ 2022-04-24 36/week @ 2022-05-01 35/week @ 2022-05-08

98 downloads per month

MIT license

11KB
176 lines

hyperid-rs Rust

Superfast id generator

This is a porting of the amazing hyperid project written in javascript.

Install

Add the dependency to your Cargo.toml:

[dependencies]
hyperid = "2"

Usage

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

cargo release  -vv --skip-publish <version>
# wait for CI
git checkout <tag>
cargo publish

License

See LICENSE file

Dependencies

~200–280KB