Crates.io | snowcloud |
lib.rs | snowcloud |
version | 0.4.0 |
source | src |
created_at | 2023-03-26 23:05:40.570487 |
updated_at | 2023-04-20 20:50:56.712374 |
description | small crate for creating custom snowflakes that provides thread safe and non thread safe generators |
homepage | https://github.com/DAC098/snowcloud |
repository | https://github.com/DAC098/snowcloud |
max_upload_size | |
id | 821554 |
size | 129,033 |
a small library for implementing custom ids based on timestamps, static ids, and sequence counters. the module provides 2 types of generators, a thread safe and non thread safe version. they allow for different types of waiting for ids if you want specific behavior. each generator is capable of using different snowflake types to allow for different snowflake formats.
// 43 bit timestamp, 8 bit primary id, 12 bit sequence
type MyFlake = snowcloud::i64::SingleIdFlake<43, 8, 12>;
type MyCloud = snowcloud::Generator<MyFlake>;
// 2023/03/23 9:00:00 in milliseconds, timestamps will start from this
// date
const START_TIME: u64 = 1679587200000;
let mut cloud = MyCloud::new(START_TIME, 1)
.expect("failed to create MyCloud");
let flake = cloud.next_id()
.expect("failed to create snowflake");
println!("{}", flake.id());
check out the docs for more information
there are additions that can be added.
since the api is fairly minimal there probably wont be too much in terms of change but just as a precaution this will not have a major version until it is finalized (open to suggestions).
fixes, improvements, or suggestions are welcome.