A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems

Overview

snowflake-rs

A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)

Build crates.io docs.rs License

A distributed unique ID generator inspired by Twitter's Snowflake.

This is a Rust implementation of the original houseme/snowflake, which is written in Go.

A Snowflake 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]
snowflake_me = "0.1"

Quickstart

use snowflake_me::Snowflake;

let mut sf = Snowflake::new().unwrap();
let next_id = sf.next_id().unwrap();
println!("{}", next_id);

Benchmarks

Run them yourself with cargo bench.

1、Benchmarks were run on a MacBook Pro (16-inch, 2019) with a 2,4GHz i9 and 64 GB memory.

test bench_decompose ... bench:         651 ns/iter (+/- 251)
test bench_new       ... bench:     795,722 ns/iter (+/- 371,556)
test bench_next_id   ... bench:      36,652 ns/iter (+/- 1,105)

2、Benchmarks were run on a MacBook Pro (15-inch, 2017) with a 2,8GHz i7 and 16 GB memory.

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.

Comments
Owner
houseme
open source houseme Contact mail
houseme
Flexible snowflake generator, reference snoyflake and leaf.

Flexible snowflake generator, reference snoyflake and leaf.

Egccri 2 May 6, 2022
Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files.

Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files. Mozilla's MDN has a good reference for CSS selector syntax.

Michael Maclean 6.3k Jan 3, 2023
Mononym is a library for creating unique type-level names for each value in Rust.

Mononym is a library for creating unique type-level names for each value in Rust.

MaybeVoid 52 Dec 16, 2022
tiny_id is a Rust library for generating non-sequential, tightly-packed short IDs.

tiny_id tiny_id is a Rust library for generating non-sequential, tightly-packed short IDs. Most other short ID generators just string together random

Paul Butler 33 Aug 6, 2022
mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices.

mach-dump mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices. It has no external dependencies. Example use std::path::Pa

Tobi 8 Sep 16, 2022
Parse hex colors to tui rgb colors

Parse hex colors to tui rgb colors

Uttarayan Mondal 1 Nov 8, 2021
A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them

Datadog Formatting Layer A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them. Features Provides a layer for t

Open Schnick 4 Jun 22, 2023
Generate bindings to use Rust code in Qt and QML

Rust Qt Binding Generator This code generator gets you started quickly to use Rust code from Qt and QML. In other words, it helps to create a Qt based

KDE GitHub Mirror 768 Dec 24, 2022
A lightweight distributed message queue. Like AWS SQS and RSMQ but on Postgres.

Postgres Message Queue (PGMQ) A lightweight distributed message queue. Like AWS SQS and RSMQ but on Postgres. Features Lightweight - Built with Rust a

Tembo 15 Jul 25, 2023
An asynchronous Hardware Abstraction Layer (HAL) for embedded systems

embedded-hal-async An asynchronous Hardware Abstraction Layer (HAL) for embedded systems. This crate contains asynchronous versions of the embedded-ha

Diego Barrios Romero 3 Jan 22, 2022
Auto Fan Management Utility in Linux Systems for Monster Laptops

Auto Fan Management Utility in Linux Systems for Monster Laptops Monster Laptoplar için Linux Sistemlerde Oto Fan Yönetimi TR Monster laptoplar gömülü

null 2 Aug 22, 2022
Artifact collection tool for *nix systems

fennec is an artifact collection tool written in Rust to be used during incident response on *nix based systems. fennec allows you to write a configuration file that contains how to collect artifacts.

AbdulRhman Alfaifi 147 Dec 19, 2022
A reactive runtime for embedded systems.

Actuate Examples A reactive diagram for robotics and control systems. Actuate leverages Rust's type system to create an efficient diagram that connect

null 7 Mar 4, 2024
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Jerel Unruh 70 Dec 13, 2022
Rust no_std, embedded_hal board support package for the Electro-Smith Daisy platform.

Daisy Rust no_std, embedded_hal board support package for the Electro-Smith Daisy platform. This project was forked from antoinevg/daisy_bsp. Supporte

zlosynth 5 Dec 4, 2022
A scrapper that abstracts the IQ Option API calls into a Rust package.

IQ Option API - In Rust An abstraction of IQ Options API calls in a Rust library. License Licensed under either of MIT license (LICENSE-MIT or https:/

Vinícius Roque 8 Jul 17, 2023
Simple and efficient time representation in Rust.

timens-rs Simple and efficient timestamp representation. The main objective being interoperability with OCaml Core_kernel.Time_ns. A significant part

Laurent Mazare 7 Oct 17, 2022
A flexible, simple to use, immutable, clone-efficient String replacement for Rust

A flexible, simple to use, immutable, clone-efficient String replacement for Rust. It unifies literals, inlined, and heap allocated strings into a single type.

Scott Meeuwsen 119 Dec 12, 2022
Czkawka is a simple, fast and easy to use app to remove unnecessary files from your computer.

Multi functional app to find duplicates, empty folders, similar images etc.

Rafał Mikrut 9.2k Jan 4, 2023