🃏 A distributed unique ID generator inspired by Twitter's Snowflake. https://docs.rs/sonyflake/
  • Rust 96.1%
  • Nix 3.9%
Find a file
Arne Bahlo 67e8e0f6d7
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fix: Remove conflicting rust-toolchain file
2025-11-29 13:29:37 +01:00
benches chore: Run cargo fmt 2025-07-20 18:00:43 +02:00
src chore: Collapse if statement 2025-11-29 13:16:50 +01:00
.gitignore chore: remove Cargo.lock from gitignore 2024-04-01 01:45:04 +11:00
.woodpecker.yaml Move to Codeberg 2025-11-29 13:27:30 +01:00
Cargo.lock chore(deps): bump thiserror from 1.0.64 to 2.0.17 2025-11-29 13:18:52 +01:00
Cargo.toml Move to Codeberg 2025-11-29 13:27:30 +01:00
CHANGELOG.md Move to Codeberg 2025-11-29 13:27:30 +01:00
flake.lock chore: Add flake.nix 2025-11-29 13:16:41 +01:00
flake.nix chore: Add flake.nix 2025-11-29 13:16:41 +01:00
LICENSE-APACHE Add licenses 2020-12-29 10:27:02 +01:00
LICENSE-MIT Add licenses 2020-12-29 10:27:02 +01:00
README.md Move to Codeberg 2025-11-29 13:27:30 +01:00
rust-toolchain.toml chore: Add flake.nix 2025-11-29 13:16:41 +01:00

sonyflake-rs

status-badge 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

  • 39 bits for time in units of 10 msec
  • 8 bits for a sequence number
  • 16 bits for a machine id

Install

Add the following to your Cargo.toml:

[dependencies]
sonyflake = "0.4"

Quickstart

use sonyflake::Sonyflake;

let sf = Sonyflake::new().unwrap();
let next_id = sf.next_id().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.

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.