Skip to main content

QubitSnowflakeGenerator

Struct QubitSnowflakeGenerator 

Source
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

Source

pub fn new(host: u64) -> Result<Self, IdError>

Creates a generator with Qubit defaults.

§Parameters
  • host: Host identifier in 0..=511.
§Returns

A configured generator.

§Errors

Returns IdError::HostOutOfRange when host does not fit in the host field.

Source

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 in 0..=511.
  • epoch: Timestamp origin.
§Returns

A configured generator using the system clock.

§Errors

Returns IdError::HostOutOfRange when host is invalid.

Source

pub fn with_clock<F>( mode: IdMode, precision: TimestampPrecision, host: u64, epoch: SystemTime, max_skew_millis: u64, clock: F, ) -> Result<Self, IdError>
where F: Fn() -> SystemTime + Send + Sync + 'static,

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 in 0..=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.

Source

pub const fn builder(&self) -> &QubitSnowflakeBuilder

Returns the Qubit bit builder.

§Returns

Builder used to compose and inspect generated IDs.

Source

pub const fn epoch(&self) -> SystemTime

Returns the configured epoch.

§Returns

Timestamp origin.

Source

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.

Trait Implementations§

Source§

impl IdGenerator<u64> for QubitSnowflakeGenerator

Source§

fn next_id(&self) -> Result<u64, Self::Error>

Generates the next Qubit snowflake ID.

Source§

type Error = IdError

Error returned when generation fails.
Source§

fn format_id(&self, id: &T) -> String
where T: Display,

Formats an already generated ID. Read more
Source§

fn next_string(&self) -> Result<String, Self::Error>
where T: Display,

Generates the next ID and formats it as a string. 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.