Crates.io | sonyflake |
lib.rs | sonyflake |
version | 0.3.0 |
source | src |
created_at | 2020-12-29 09:57:41.473099 |
updated_at | 2024-10-09 08:54:51.184288 |
description | A distributed unique ID generator inspired by Twitter's Snowflake |
homepage | |
repository | https://github.com/bahlo/sonyflake-rs |
max_upload_size | |
id | 328691 |
size | 35,433 |
A distributed unique ID generator inspired by Twitter's Snowflake.
This is a Rust implementation of the original sony/sonyflake, which is written in Go.
A Sonyflake ID is composed of
Add the following to your Cargo.toml
:
[dependencies]
sonyflake = "0.3"
use sonyflake::Sonyflake;
let sf = Sonyflake::new().unwrap();
let next_id = sf.next_id().unwrap();
println!("{}", next_id);
Benchmarks were run on a MacBook Pro (15-inch, 2017) with a 2,8GHz i7 and 16 GB memory.
Run them yourself with cargo bench
.
test bench_decompose ... bench: 1,066 ns/iter (+/- 132)
test bench_new ... bench: 738,129 ns/iter (+/- 318,192)
test bench_next_id ... bench: 37,390 ns/iter (+/- 499)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.