Struct rusty_snowflake::Snowflake
source · pub struct Snowflake {
pub worker_id: u64,
pub sequence: u64,
pub last_timestamp: u64,
}
Fields§
§worker_id: u64
§sequence: u64
§last_timestamp: u64
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