pub struct Snowflake {
pub worker_id: u64,
pub sequence: u64,
pub timestamp: u64,
}
Fields§
§worker_id: u64
The worker ID of the snowflake. This is a unique identifier for the host or thread that created the snowflake.
sequence: u64
The sequence number of the snowflake. This increments every time the snowflake is created within the same second. This will automatically reset to 0 when the timestamp changes or when the sequence overflows (2^16 - 1).
timestamp: u64
The timestamp of the snowflake creation in seconds since the epoch (1970-01-01 00:00:00 UTC).
Implementations§
Source§impl Snowflake
impl Snowflake
Sourcepub fn next(&self) -> Snowflake
pub fn next(&self) -> Snowflake
Generate a new snowflake ID This function will return a new snowflake ID every time it is called with the same worker ID. If the timestamp is the same as the previous call, the sequence number will be incremented.
§Returns
A new snowflake ID
§Example
use rusty_snowflake::Snowflake;
let snowflake = Snowflake::new(420);
let next = snowflake.next();
println!("{}", next);
println!("{}", next.next());
Trait Implementations§
Source§impl Ord for Snowflake
impl Ord for Snowflake
Source§impl PartialOrd for Snowflake
impl PartialOrd for Snowflake
impl Copy for Snowflake
impl Eq for Snowflake
impl StructuralPartialEq for Snowflake
Auto Trait Implementations§
impl Freeze for Snowflake
impl RefUnwindSafe for Snowflake
impl Send for Snowflake
impl Sync for Snowflake
impl Unpin for Snowflake
impl UnwindSafe for Snowflake
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more