pub struct QubitSnowflakeGenerator { /* private fields */ }Expand description
Qubit Snowflake generator.
This generator uses the Qubit fixed-header layout, including mode and
precision bits. The default constructor uses sequential mode, second
precision, host 0, and epoch 2018-12-02T00:00:00Z.
Implementations§
Source§impl QubitSnowflakeGenerator
impl QubitSnowflakeGenerator
Sourcepub fn new(host: u64) -> Result<Self, IdError>
pub fn new(host: u64) -> Result<Self, IdError>
Creates a generator with Qubit defaults.
§Parameters
host: Host identifier in0..=511.
§Returns
A configured generator.
§Errors
Returns IdError::HostOutOfRange when host does not fit in the host
field.
Sourcepub fn with_options(
mode: IdMode,
precision: TimestampPrecision,
host: u64,
epoch: SystemTime,
) -> Result<Self, IdError>
pub fn with_options( mode: IdMode, precision: TimestampPrecision, host: u64, epoch: SystemTime, ) -> Result<Self, IdError>
Creates a generator with an explicit layout and epoch.
§Parameters
mode: ID ordering mode.precision: Timestamp precision.host: Host identifier in0..=511.epoch: Timestamp origin.
§Returns
A configured generator using the system clock.
§Errors
Returns IdError::HostOutOfRange when host is invalid.
Sourcepub fn with_clock<F>(
mode: IdMode,
precision: TimestampPrecision,
host: u64,
epoch: SystemTime,
max_skew_millis: u64,
clock: F,
) -> Result<Self, IdError>
pub fn with_clock<F>( mode: IdMode, precision: TimestampPrecision, host: u64, epoch: SystemTime, max_skew_millis: u64, clock: F, ) -> Result<Self, IdError>
Creates a generator with an explicit clock.
This constructor is useful for deterministic tests and for embedding the generator in systems that already provide a clock abstraction.
§Parameters
mode: ID ordering mode.precision: Timestamp precision.host: Host identifier in0..=511.epoch: Timestamp origin.max_skew_millis: Maximum tolerated backwards clock movement in milliseconds.clock: Function returning the current time.
§Returns
A configured generator.
§Errors
Returns IdError::HostOutOfRange when host is invalid.
Sourcepub const fn builder(&self) -> &QubitSnowflakeBuilder
pub const fn builder(&self) -> &QubitSnowflakeBuilder
Sourcepub const fn epoch(&self) -> SystemTime
pub const fn epoch(&self) -> SystemTime
Sourcepub fn generate_at(
&self,
time: SystemTime,
sequence: u64,
) -> Result<u64, IdError>
pub fn generate_at( &self, time: SystemTime, sequence: u64, ) -> Result<u64, IdError>
Generates an ID for an explicit time and sequence.
§Parameters
time: Time to encode.sequence: Sequence value inside the encoded time slice.
§Returns
Encoded ID.
§Errors
Returns IdError::TimeBeforeEpoch if time is before the configured
epoch. Returns builder validation errors if the computed timestamp or
provided sequence does not fit.