id-generator

Crates.ioid-generator
lib.rsid-generator
version0.3.0
sourcesrc
created_at2021-12-06 16:04:37.263562
updated_at2022-07-07 16:23:20.957847
descriptiongenerate id
homepagehttps://github.com/get200/id-generator
repositoryhttps://github.com/get200/id-generator
max_upload_size
id493270
size92,285
xieke (get200)

documentation

README

Example

Dependencies:

[dependencies]
id-generator = "0.3.0"

Code:

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

fn main() {
    let mut config = SnowflakeConfig::new();
    config.base_timestamp = Utc.ymd(2022, 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);
}

/// basic53
use chrono::{TimeZone, Utc};
use id_generator::snowflake53::{self, SnowflakeConfig};

fn main() {
    let mut config = SnowflakeConfig::new();
    config.base_seconds = Utc.ymd(2022, 1, 1).and_hms(0, 0, 0).timestamp();
    config.worker_id = 0;
    // ...
    snowflake53::set_config(config);

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

Commit count: 9

cargo fmt