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.