Skip to main content

Sequence

Struct Sequence 

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

The uniqueness source: a process-unique, time-derived base plus an atomic counter. Generated factory modules hold one per model:

static SEQ: Sequence = Sequence::new();
// …
id: self.id.resolve(f, |_| Set::Value(SEQ.next_i64())),

Two promises, in order of strength:

  • In-process, values never repeat — the counter is atomic, so create_many(&db, 100) (and every factory call across every test in the binary) draws distinct values.
  • Across processes, collision is improbable — the base is taken from the clock at first use (the same shape the Layer 2 spec’s key() pinned), so runs against a shared persistent server land in different ranges. Improbable, not impossible: this is test-data machinery, not a coordination service.

Values are positive and fit i32, so the one sequence serves integer (PostgreSQL/MySQL) and INTEGER (SQLite) primary keys alike.

Deliberately outside the Faker seed: sequences exist for uniqueness, and a reproducible primary key against a shared server would reproduce a collision (crate docs, “the determinism switch”).

Implementations§

Source§

impl Sequence

Source

pub const fn new() -> Self

A fresh sequence; const, so it can be a static in a generated module. The base is drawn from the clock on first use, not here.

Source

pub fn next_i32(&self) -> i32

The next value, i32-typed for dialects whose integer is 32-bit.

Source

pub fn next_i64(&self) -> i64

The next value, widened — the same counter as next_i32, for i64-typed columns.

Trait Implementations§

Source§

impl Debug for Sequence

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Sequence

Source§

fn default() -> Self

Returns the “default value” for a type. 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.