Struct MonteFlake

Source
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

Source

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)

Source

pub fn epoch(self, epoch: u64) -> MonteFlake

Set the epoch of a MonteFlake generator

Source

pub fn id(self, id: u64) -> MonteFlake

Set the id of a MonteFlake generator

Source

pub fn bitwidths(self, ts_bits: u64, id_bits: u64) -> MonteFlake

Set the bitwidths of a MonteFlake generator

Source

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

Source

pub 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

Source

pub 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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.