Struct monteflake::MonteFlake
[−]
[src]
pub struct MonteFlake { // some fields omitted }
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.
Methods
impl MonteFlake
[src]
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)
fn epoch(self, epoch: u64) -> MonteFlake
Set the epoch of a MonteFlake generator
fn id(self, id: u64) -> MonteFlake
Set the id of a MonteFlake generator
fn bitwidths(self, ts_bits: u64, id_bits: u64) -> MonteFlake
Set the bitwidths of a MonteFlake generator
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
fn encode(&self, ts: u64, id: u64, seq: u64) -> u64
encode into an id the current time, id of the generator (machine, node, shard), and sequence value the current time (ts) is the number of milliseconds passed since the unix epoch
fn decode(&self, flake_id: u64) -> (u64, u64, u64)
decode from an encoded id the time, id of the generator, and sequence id the current time (ts) is the number of milliseconds passed since the unix epoch