| Crates.io | k-snowflake |
| lib.rs | k-snowflake |
| version | 2.1.1 |
| created_at | 2025-02-08 16:39:31.092728+00 |
| updated_at | 2025-04-24 21:39:29.706542+00 |
| description | Simple one-dependency implementation of Twitter`s (X) snowflake in rust |
| homepage | https://github.com/KryptonFox/k-snowflake |
| repository | https://github.com/KryptonFox/k-snowflake |
| max_upload_size | |
| id | 1548149 |
| size | 50,310 |
Simple one-dependency implementation of Twitter`s (X) snowflake in rust. Compatible with discord snowflakes. Firstly used for my projects. One snowflake creation take ~52ns. See /benches.
Twitter snowflake schema

Snowflakes are 64 bits in binary. (Only 63 are used to fit in a signed integer.) The first 41 bits are a timestamp, representing milliseconds since the chosen epoch (default X epoch is 1288834974657 (in Unix time milliseconds)) . The next 10 bits represent a machine ID, preventing clashes. Twelve more bits represent a per-machine sequence number, to allow creation of multiple snowflakes in the same millisecond. The final number is generally serialized in decimal
use k_snowflake::{create_snowflake, set_epoch, Snowflake, DISCORD_EPOCH};
fn main() {
// Create snowflake
let snowflake = create_snowflake();
println!("{}", snowflake);
// change epoch
set_epoch(DISCORD_EPOCH);
let snowflake = create_snowflake();
println!("{}", snowflake);
// get UNIX timestamp of discord snowflake
println!(
"{}",
"1301619246953926811"
.parse::<Snowflake>()
.unwrap()
.get_unix_timestamp()
);
}
See other methods in docs