pub struct Generator { /* private fields */ }Expand description
Generator with pre-injected state - no state lookup needed during generation
Implementations§
Source§impl Generator
impl Generator
pub fn new( config: Config, worker_id: u64, process_id: u64, ) -> Result<Self, ValidationError>
pub fn new_with_state( config: Config, state: Arc<State>, worker_id: u64, process_id: u64, ) -> Result<Self, ValidationError>
Sourcepub fn generate_internal(&self) -> Result<u64, GeneratorError>
pub fn generate_internal(&self) -> Result<u64, GeneratorError>
Generate ID (returns error on sequence exhaustion)
Sourcepub fn compose(
&self,
timestamp: u64,
sequence: u64,
) -> Result<u64, ValidationError>
pub fn compose( &self, timestamp: u64, sequence: u64, ) -> Result<u64, ValidationError>
Compose ID with validation (uses bound worker_id and process_id)
Sourcepub fn compose_unchecked(&self, timestamp: u64, sequence: u64) -> u64
pub fn compose_unchecked(&self, timestamp: u64, sequence: u64) -> u64
Compose ID without validation (uses bound worker/process, masks overflow)
Sourcepub fn process_id(&self) -> u64
pub fn process_id(&self) -> u64
Get the process_id this generator is bound to
Sourcepub fn components(&self, id: u64) -> IdComponents
pub fn components(&self, id: u64) -> IdComponents
Get the ID components as a struct
Sourcepub fn decompose(&self, id: u64) -> (u64, u64, u64, u64)
pub fn decompose(&self, id: u64) -> (u64, u64, u64, u64)
Decompose the ID into its components as a tuple
Sourcepub fn extract_timestamp(&self, id: u64) -> u64
pub fn extract_timestamp(&self, id: u64) -> u64
Extract just the timestamp component from an ID
Sourcepub fn extract_worker_id(&self, id: u64) -> u64
pub fn extract_worker_id(&self, id: u64) -> u64
Extract just the worker ID component from an ID
Sourcepub fn extract_process_id(&self, id: u64) -> u64
pub fn extract_process_id(&self, id: u64) -> u64
Extract just the process ID component from an ID
Sourcepub fn extract_sequence(&self, id: u64) -> u64
pub fn extract_sequence(&self, id: u64) -> u64
Extract just the sequence component from an ID
Sourcepub fn compose_custom(
&self,
timestamp: u64,
worker_id: u64,
process_id: u64,
sequence: u64,
) -> Result<u64, ValidationError>
pub fn compose_custom( &self, timestamp: u64, worker_id: u64, process_id: u64, sequence: u64, ) -> Result<u64, ValidationError>
Compose an ID from individual components with validation
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Generator
impl RefUnwindSafe for Generator
impl Send for Generator
impl Sync for Generator
impl Unpin for Generator
impl UnwindSafe for Generator
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