Generator

Struct Generator 

Source
pub struct Generator { /* private fields */ }
Expand description

Generator with pre-injected state - no state lookup needed during generation

Implementations§

Source§

impl Generator

Source

pub fn new( config: Config, worker_id: u64, process_id: u64, ) -> Result<Self, ValidationError>

Source

pub fn new_with_state( config: Config, state: Arc<State>, worker_id: u64, process_id: u64, ) -> Result<Self, ValidationError>

Source

pub fn generate_internal(&self) -> Result<u64, GeneratorError>

Generate ID (returns error on sequence exhaustion)

Source

pub fn generate(&self) -> u64

Generate ID, blocking on sequence exhaustion

Source

pub fn compose( &self, timestamp: u64, sequence: u64, ) -> Result<u64, ValidationError>

Compose ID with validation (uses bound worker_id and process_id)

Source

pub fn compose_unchecked(&self, timestamp: u64, sequence: u64) -> u64

Compose ID without validation (uses bound worker/process, masks overflow)

Source

pub fn worker_id(&self) -> u64

Get the worker_id this generator is bound to

Source

pub fn process_id(&self) -> u64

Get the process_id this generator is bound to

Source

pub fn components(&self, id: u64) -> IdComponents

Get the ID components as a struct

Source

pub fn decompose(&self, id: u64) -> (u64, u64, u64, u64)

Decompose the ID into its components as a tuple

Source

pub fn extract_timestamp(&self, id: u64) -> u64

Extract just the timestamp component from an ID

Source

pub fn extract_worker_id(&self, id: u64) -> u64

Extract just the worker ID component from an ID

Source

pub fn extract_process_id(&self, id: u64) -> u64

Extract just the process ID component from an ID

Source

pub fn extract_sequence(&self, id: u64) -> u64

Extract just the sequence component from an ID

Source

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

Source

pub fn compose_custom_unchecked( &self, timestamp: u64, worker_id: u64, process_id: u64, sequence: u64, ) -> u64

Compose from all components without validation (values exceeding limits are masked)

Trait Implementations§

Source§

impl Debug for Generator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.