Skip to main content

Factory

Trait Factory 

Source
pub trait Factory<M>: Sized {
    // Required method
    fn definition() -> M;

    // Provided method
    fn make_many(count: usize) -> Vec<M> { ... }
}
Expand description

A model factory. Generates randomized fake instances of M for tests/dev.

Mirrors Laravel’s Post::factory()->count(50)->create(). The definition() method returns a single random instance; make_many() / create_many() generate batches.

Required Methods§

Source

fn definition() -> M

Generate one random in-memory instance.

Provided Methods§

Source

fn make_many(count: usize) -> Vec<M>

Generate count random in-memory instances (not persisted).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§