#snowflake #twitter #id-generator #thread-safety #multi-threaded #algorithm #generate

snowflake-multi-threaded

The rust-lang implementation of Twitter's id generator algorithm snowflake, it thread safety | Twitter 的id生成器算法snowflake的rust-lang 实现

2 releases

Uses old Rust 2015

0.1.4 Jul 4, 2019
0.1.3 Jul 4, 2019
0.1.2 Jul 4, 2019
0.1.1 Mar 28, 2018
0.1.0 Mar 27, 2018

#867 in Concurrency

32 downloads per month
Used in yar_client

MIT license

8KB
101 lines

snowflake-rust

snowflake is a lib for generating unique ID

this project is rust-lang implementation of Twitter's id generator algorithm snowflake

Twitter 的id生成器算法snowflake的rust-lang 实现

Build Status

Usage

Add this to your Cargo.toml:

[dependencies]
snowflake-multi-threaded = "0.1.0"
 let workerId:i64 = 1;
 let datacenterId:i64 = 1;
 let mut id_gen = SnowFlakeId::new(workerId,datacenterId);
 println!("{}", id_gen.generate().unwrap());

lib.rs:

Generate id with the type i64

Examples

use snowflake_multi_threaded::SnowFlakeId;

let worker_id:i64 = 1;
let datacenter_id:i64 = 1;
let mut id_gen = SnowFlakeId::new(worker_id,datacenter_id);
assert!(id_gen.generate_id().is_ok());

Dependencies

~0.6–1MB
~15K SLoC