2 unstable releases

Uses new Rust 2021

0.2.0 Dec 7, 2021
0.1.0 Dec 6, 2021

#8 in #snowflake

22 downloads per month

MIT/Apache

6KB
128 lines

Example

Dependencies:

[dependencies]
id-generator = "0.2.0"

Code:

use chrono::{TimeZone, Utc};
use id_generator::snowflake::{self, SnowflakeConfig};

fn main() {
    let mut config = SnowflakeConfig::new();
    config.base_timestamp = Utc.ymd(2021, 1, 1).and_hms(0, 0, 0).timestamp_millis();
    config.datacenter_id = 0;
    config.worker_id = 0;
    // ...
    snowflake::set_config(config);

    let id = snowflake::next_id();
    println!("{}", id);
}

Dependencies

~1MB
~14K SLoC