Struct rusty_snowflake::Snowflake
source · pub struct Snowflake {
pub worker_id: u64,
pub sequence: u64,
pub last_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).
last_timestamp: u64
The timestamp of the last snowflake creation in seconds since the epoch (1970-01-01 00:00:00 UTC).
Implementations§
source§impl Snowflake
impl Snowflake
pub fn new(worker_id: u64) -> Snowflake
sourcepub fn next(&mut self) -> u64
pub fn next(&mut self) -> u64
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.
Example
use rusty_snowflake::Snowflake;
let mut snowflake = Snowflake::new(1);
println!("{}", snowflake.next());
println!("{}", snowflake.next());
Trait Implementations§
source§impl PartialEq<Snowflake> for Snowflake
impl PartialEq<Snowflake> for Snowflake
impl Eq for Snowflake
impl StructuralEq for Snowflake
impl StructuralPartialEq for Snowflake
Auto Trait Implementations§
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