A module for quickly generating IDs guaranteed to be unique within the current process, for the lifetime of the current process.
API Docs: https://stebalien.github.io/snowflake/snowflake/
The unique ID's are sizeof(usize) + 64
bits wide and are generated by combining a
usize
global counter value with a 64bit thread local offset. This is important because each
thread that calls new()
at least once will reserve at least 2^64 IDs. So, the only way to
run out of IDs in a reasonable amount of time is to run a 32bit system, spawn 2^32 threads, and
claim one ID on each thread. You might be able to do this on a 64bit system but it would take a
while... TL; DR: Don't create unique IDs from over 4 billion different threads on a 32bit system.