2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 5, 2024

#849 in Text processing

Apache-2.0

8KB
152 lines

A next-generation, customizable and simple ID system, built in Rust.


Crates.io Version GitHub License

Features

  • Simple. Akai generates beautiful, minimal IDs that are unique.
  • Customizable. You can personalize the prefix, the starting timestamp, and you can use a node ID.
  • Robust. Akai is built in Rust, the world's most loved programming language.
  • Safe. It is impossible to generate a duplicate ID, due to the uniqueness of Superflake combined with random characters.

Install

Put the desired version of the crate into the dependencies section of your Cargo.toml:

[dependencies]
akai = { version = "0.1.0" }

The ID

Akai IDs consist of 3 sections: the prefix, the Superflake and the tail, which is simply a cryptographically secure random string.

Superflake

Superflake is a revolutionary identification technology based on Twitter's Snowflake. Superflake is generated by concatenating:

  • a 42-bit timestamp,
  • a 10-bit node ID, and
  • a 12-bit sequential number.

Example

use akai::{Akai, AkaiPrefix, AkaiOptions};

let prefix = AkaiPrefix {
    content: "user".to_string(),
    allows_lowercase: true
};
    
let akai = Akai::new(AkaiOptions {
    prefix,
    custom_bytes: Some(8),
    custom_timestamp: None
});
    
match akai.generate() {
    Ok(id) => println!("{}", id),
    Err(error) => eprintln!("Error: {}", error)
}

Dependencies

~2.5–3.5MB
~60K SLoC