pub struct MonteFlake { /* private fields */ }
Expand description
MonteFlake creates a configurable Snowflake ID generator where the epoch and bitwidths may be adjusted to your liking from the defaults. MonteFlake id generation will always increase in value from the time its instantiated. No other guarantees are made. If a MonteFlake generator is created after a clock moves back from other MonteFlake generated ids conflicting ID values are entirely possible.
Implementations§
Source§impl MonteFlake
impl MonteFlake
Sourcepub fn new(id: u64) -> MonteFlake
pub fn new(id: u64) -> MonteFlake
Build a new monteflake with default options id: 0 epoch: 2013-01-01T00:00:00Z in milliseconds since the unix epoch bitwidths (42 timestamp bits, 10 id bits, 12 sequence bits)
Sourcepub fn epoch(self, epoch: u64) -> MonteFlake
pub fn epoch(self, epoch: u64) -> MonteFlake
Set the epoch of a MonteFlake generator
Sourcepub fn id(self, id: u64) -> MonteFlake
pub fn id(self, id: u64) -> MonteFlake
Set the id of a MonteFlake generator
Sourcepub fn bitwidths(self, ts_bits: u64, id_bits: u64) -> MonteFlake
pub fn bitwidths(self, ts_bits: u64, id_bits: u64) -> MonteFlake
Set the bitwidths of a MonteFlake generator
Sourcepub fn next(&mut self) -> u64
pub fn next(&mut self) -> u64
generate the next id internally this updates at least the current sequence value, possibly the timestamp value if enough time has elapsed to matter