sonyflake-rs

Build crates.io docs.rs License

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

Install

Add the following to your Cargo.toml: toml [dependencies] sonyflake = "0.2"

Quickstart

```rust use sonyflake::Sonyflake;

let sf = Sonyflake::new().unwrap(); let nextid = sf.nextid().unwrap(); println!("{}", next_id); ```

Benchmarks

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.

benchmark 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)

License

Licensed under either of

at your option.

Contribution

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.