Skip to main content

Source

Enum Source 

Source
pub enum Source<T> {
    Auto,
    Value(T),
    Null,
    Omit,
    Gen(Arc<dyn Fn(&mut Faker) -> T + Send + Sync>),
}
Expand description

One column of a factory template: where the value comes from.

A template field holds a Source<T>, and mods rewrite it — fac::users::id(10) sets Source::Value, fac::users::random_id() sets a Source::Gen. At build time resolve turns the source into the three-state Set the model’s Setter wants, with the template’s own default rule filling Auto.

Why five states where Set has three: a template needs to distinguish “let the template’s default rule decide” (Auto) from “leave the column out of the statement” (Omit) — in a Setter those collapse into Unset, but in a factory the first means “sequence/random/whatever the spec says” and the second means “the database default, explicitly”.

Variants§

§

Auto

The template’s default rule decides — a sequence value for a unique column, a random value for a data column, omission for a column whose database default is the point.

§

Value(T)

Exactly this value.

§

Null

SQL NULL, explicitly.

§

Omit

Leave the column out of the statement — the database default applies.

§

Gen(Arc<dyn Fn(&mut Faker) -> T + Send + Sync>)

A caller-supplied generator, drawing from the run’s Faker — so a custom random source is still covered by the determinism switch.

Implementations§

Source§

impl<T> Source<T>

Source

pub fn from_fn(g: impl Fn(&mut Faker) -> T + Send + Sync + 'static) -> Self

A generated value: Source::from_fn(|f| f.i64_in(1, 1000)).

Source§

impl<T: Clone> Source<T>

Source

pub fn resolve( &self, f: &mut Faker, auto: impl FnOnce(&mut Faker) -> Set<T>, ) -> Set<T>

The Set this source contributes, with auto — the template’s per-column default rule — deciding Auto. auto returns a Set rather than a T so a rule can itself be “omit” (a column whose database default is the right test value).

Trait Implementations§

Source§

impl<T: Clone> Clone for Source<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Source<T>

Source§

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

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

impl<T> Default for Source<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Source<T>

§

impl<T> !UnwindSafe for Source<T>

§

impl<T> Freeze for Source<T>
where T: Freeze,

§

impl<T> Send for Source<T>
where T: Send,

§

impl<T> Sync for Source<T>
where T: Sync,

§

impl<T> Unpin for Source<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Source<T>
where T: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.