#snowflake #snowflake-id #distributed-systems #twitter #datacenter

qanik

A simple rust implementation of twitter's SnowFlake

1 unstable release

0.1.1 Jan 2, 2025

#2 in #datacenter

Custom license

6KB
79 lines

About the project

qanik is a simple rust implementation of twitters SnowFlake.

Built with

  • rustc 1.83.0

Getting started

Add qanik to your cargo dependencies.
Ex:

[dependencies]
    
qanik = "0.1.0"

License

Distributed under the MIT License. See LICENSE.txt for more information.


lib.rs:

A simple rust implementation of twitter's snowflake id

Twitters snowflake id is highly useful for distributed systems. It consists of a 41 bit timestamp, a 5 bit datacenter id, 5 bit machine/node id and a 12 bit sequence.

Example

use qanik::SnowFlake;


 let snowflake: SnowFlake = SnowFlake::new(1, 1)
    .expect("Datacenter or machine id is too big.");
 let id: u64 = snowflake.generate_id();
 // Use the generated id to persist any record

Dependencies

~135KB