6 releases (breaking)

0.6.0 Mar 14, 2022
0.5.0 Jan 25, 2021
0.4.0 Dec 30, 2020
0.3.0 Nov 2, 2020
0.1.0 Aug 10, 2020

#599 in Development tools

Download history 2075/week @ 2024-07-21 2152/week @ 2024-07-28 1588/week @ 2024-08-04 1739/week @ 2024-08-11 2277/week @ 2024-08-18 1920/week @ 2024-08-25 2269/week @ 2024-09-01 2539/week @ 2024-09-08 2026/week @ 2024-09-15 1672/week @ 2024-09-22 1734/week @ 2024-09-29 1951/week @ 2024-10-06 1952/week @ 2024-10-13 1972/week @ 2024-10-20 2137/week @ 2024-10-27 1639/week @ 2024-11-03

7,887 downloads per month
Used in 5 crates (4 directly)

MIT license

13KB
114 lines

snowflake-rs

Rust version of the Twitter snowflake algorithm .

A crate for quick generating distributed-ids.

API Docs: https://docs.rs/rs-snowflake

Usage

Add this to your Cargo.toml:

[dependencies]
rs-snowflake = "*"

Getting Started

use snowflake::SnowflakeIdGenerator;
fn main() {
   let mut id_generator_generator = SnowflakeIdGenerator::new(1, 1);
   let id = id_generator_generator.real_time_generate();
}
use snowflake::SnowflakeIdBucket;
fn main() {
   let mut id_generator_bucket = SnowflakeIdBucket::new(1, 1);
   let id = id_generator_bucket.get_id();
}
test bench_generate_get_id_by_bucket                      ... bench:           5 ns/iter (+/- 0)

test bench_generate_get_id_by_generator_general_version   ... bench:         232 ns/iter (+/- 32)

test bench_generate_get_id_by_generator_lazy_version      ... bench:           2 ns/iter (+/- 0)

test bench_generate_get_id_by_generator_real_time_version ... bench:         249 ns/iter (+/- 22)

test bench_generate_ids_by_bucket                         ... bench:      13,077 ns/iter (+/- 1,263)

License

Licensed under

Contribution

Thank you all very much for your contributions to the project, and if there is anything I can do to help, I would love to help!

No runtime deps