3 unstable releases

0.2.0 May 22, 2023
0.1.1 May 20, 2023
0.1.0 May 20, 2023

#184 in Parser tooling

Download history 74/week @ 2024-03-12 62/week @ 2024-03-19 8/week @ 2024-03-26 49/week @ 2024-04-02 53/week @ 2024-04-09 79/week @ 2024-04-16 49/week @ 2024-04-23 15/week @ 2024-04-30 15/week @ 2024-05-07 34/week @ 2024-05-14 26/week @ 2024-05-21 88/week @ 2024-05-28 84/week @ 2024-06-04 49/week @ 2024-06-11 64/week @ 2024-06-18 38/week @ 2024-06-25

249 downloads per month

MIT license

17KB
274 lines

rusty-snowflake

Crates.io Version Crates.io License Tests docs.rs

This library is a Snowflake ID generator and parser written entirely in Rust.

Features

  • Generate unique snowflake IDs based on timestamp, worker ID, and sequence number.
  • Parse snowflake IDs to retrieve timestamp, worker ID, and sequence number.

Installation

Add the following dependency to your Cargo.toml file:

[dependencies]
rusty-snowflake = "0.2.0"

Or run the following in your project directory

cargo add rusty-snowflake

Usage

use rusty_snowflake::SnowflakeGenerator;

fn main() {
    // Create a new snowflake generator with custom worker ID of 123
    let mut generator = SnowflakeGenerator::new(123);

    // Generate a new snowflake ID
    let snowflake = generator.next();
    println!("Generated snowflake id: {}", snowflake);

    // Parse the snowflake ID
    let parsed_snowflake = Snowflake::parse(snowflake.to_id());
    println!("Parsed snowflake: {:?}", parsed_snowflake);
}

Contributions

Contributions and feedback are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

No runtime deps