| Crates.io | snowprints |
| lib.rs | snowprints |
| version | 0.1.1 |
| created_at | 2025-12-05 06:20:29.963712+00 |
| updated_at | 2025-12-14 23:39:12.83748+00 |
| description | Generate snowflake IDs across logical volumes |
| homepage | |
| repository | https://github.com/w-lfpup/snowprints-rs |
| max_upload_size | |
| id | 1967784 |
| size | 20,153 |
Distribute snowflake ids across available logical volumes.
Snowprints-rs is available on crates.io
cargo add snowprints
Or install directly from github:
cargo add --git https://github.com/w-lfpup/snowprints-rs
Define a Params struct.
The logical_volume_base property defines where to begin logical volume rotations. The logical_volume_length property defines how many logical volumes will be rotated.
use snowprints::Params;
// THIS VALUE CANNOT BE CHANGED FOR THE ENTIRE SOFTWARE / SYSTEM LIFETIME
const JANUARY_1ST_2024_AS_MS: u64 = 1704096000000;
let params = Params {
origin_time_ms: JANUARY_1ST_2024_AS_MS,
logical_volume_base: 0,
logical_volume_length: 8192,
};
In the example below, Snowprints start on 2024 Jan 1st and rotate through logical volumes 0-8191.
use snowprints::Snowprints;
let mut snowprints = match Snowprints::from(params) {
Ok(snow) => snow,
Err(e) => return println!("{}", e),
};
// create a unique id
let snowflake_id = match snowprints.create_id() {
Ok(sp) => sp,
Err(e) => return println!("{}", e),
};
// get the current timestamp
let timestamp = snowprints.get_timestamp();
// get a shifted timestamp to search / index / paginate DB entries
let offset_ms = 5;
let bit_shifted_timestamp = snowprints.get_bit_shifted_timestamp(offset_ms);
To pull values from a snowflake id use the decompose function.
use snowprints::decompose;
let (timestamp_ms, logical_volume, sequence) = decompose(snowprint);
A snowprint is a snowflake id variant based on this article and optimistically distributes a "sequential trail" of snowflake IDs across shardable real estate.
Snowprints :
Snowprints is released under the BSD 3-Clause License.