T1
t1ltxz-gxd/tiltflake
A strict, time-traveling Snowflake ID generator for Rust โ with timewalk from RFC3339, epoch millis, or UTC.
A strict, deterministic, and time-traveling Snowflake ID generator for Rust โ supports timewalk generation from SystemTime, DateTime, epoch milliseconds, or RFC3339 strings.
๐งฉ Installation
Add the following to your Cargo.toml file:
[dependencies]
tiltflake = {version = "*", features = ["serde"]}๐ Usage
Generate a Snowflake ID with a UNIX epoch
use tiltflake::Tiltflake;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let generator = Tiltflake::builder().build(); // Default machine_id is 1 and epoch is Unix
let id = generator.generate_from_rfc3339("2025-04-08T12:00:00Z", 0)?;
println!("Snowflake ID: {}", id);
let (dt, machine_id, seq) = generator.parse(id);
println!(
"Parsed: {}, machine_id={}, sequence={}",
dt, machine_id, seq
);
Ok(())
}Generate a Snowflake ID with a custom epoch
use chrono::{TimeZone, Utc};
use tiltflake::{EpochType, Tiltflake};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let epoch = EpochType::Custom(
Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).single().unwrap(),
);
let generator = Tiltflake::builder()
.with_epoch(epoch)
.with_machine_id(1)
.build();
let id = generator.generate_from_rfc3339("2025-04-08T12:00:00Z", 0)?;
println!("Snowflake ID: {}", id);
let (dt, machine_id, seq) = generator.parse(id);
println!(
"Parsed: {}, machine_id={}, sequence={}",
dt, machine_id, seq
);
Ok(())
}Generate a Snowflake ID with a custom Discord epoch
use tiltflake::{EpochType, Tiltflake};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let generator = Tiltflake::builder()
.with_machine_id(1)
.with_epoch(EpochType::Discord)
.build();
let id = generator.generate_from_rfc3339("2025-04-08T12:00:00Z", 0)?;
println!("Snowflake ID: {}", id);
let (dt, machine_id, seq) = generator.parse(id);
println!(
"Parsed: {}, machine_id={}, sequence={}",
dt, machine_id, seq
);
Ok(())
}See all examples in the examples folder.
๐ค Contributing
Contributions are what make the open source community an amazing place to learn, be inspired, and create.
Any contributions you make are greatly appreciated.
- Fork the repository
- Clone your fork
git clone https://github.com/t1ltxz-gxd/tiltflake.git - Create your feature branch
git checkout -b feat-smth-amazing - Stage changes
git add . - Commit your changes
git commit -m 'feat: add some amazing feature'- Use Conventional Commits for commit messages.
- Use
fix,feat,docs,style,refactor,perf,test,choreprefixes. - Use the present tense ("add feature" not "added feature").
- Use the imperative mood ("move cursor to..." not "moves cursor to...").
- Limit the first line to 72 characters or less.
- Reference issues and pull requests liberally after the first line.
- Push to the branch
git push origin feat-smth-amazing - Submit a pull request
โค๏ธ Credits
Released with โค๏ธ by Tilt.
On this page
MIT License
Created April 8, 2025
Updated March 3, 2026
