Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Generate A ksuid For A Specific Date And Time In Rust

I use truncated KSUIDs as IDs for content on my site. The shortcut I use to make a new posts adds them automatically. Older ones sometimes don't have them but generally have a date in the metadata. KSUIDs are sortable by date and while I don't use them specifically for that purpose I do like the idea of keeping them in order when possible.

This is the Rust process I use to make a new KSUID for a specific date.

rust
use svix_ksuid::*;
use time::macros::datetime;

fn main() {
    let raw_ksuid = Ksuid::new(Some(datetime!(2017-02-01 12:12:01 UTC)), None);
    let ksuid_string = raw_ksuid.to_string();
    println!("{}", ksuid_string);
}