pub trait Factory<M>:
Sized
+ Send
+ Sync{
// Required method
fn definition(&self) -> M;
// Provided methods
fn make_one(&self) -> M { ... }
fn count(self, count: usize) -> FactoryBuilder<M, Self> { ... }
fn state<F>(self, modifier: F) -> FactoryBuilder<M, Self>
where F: Fn(&mut M) + Send + Sync + 'static { ... }
fn create_one<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
) -> Pin<Box<dyn Future<Output = Result<M, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn create_many<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
count: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<M>, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Expand description
Trait Factory — Pondasi pembuatan data mock/dummy untuk pengujian dan seeding ala Laravel.
Required Methods§
Sourcefn definition(&self) -> M
fn definition(&self) -> M
Definisikan nilai atribut default untuk sebuah instance model
Provided Methods§
Sourcefn count(self, count: usize) -> FactoryBuilder<M, Self>
fn count(self, count: usize) -> FactoryBuilder<M, Self>
Menentukan jumlah record yang akan dibuat (fluent method chaining)
Sourcefn state<F>(self, modifier: F) -> FactoryBuilder<M, Self>
fn state<F>(self, modifier: F) -> FactoryBuilder<M, Self>
Menambahkan state modifier untuk mengubah nilai field tertentu
Sourcefn create_one<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
) -> Pin<Box<dyn Future<Output = Result<M, AppError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn create_one<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
) -> Pin<Box<dyn Future<Output = Result<M, AppError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Menyimpan 1 instance model langsung ke database dan memuat ulang record dari DB
Sourcefn create_many<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
count: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<M>, AppError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn create_many<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 DatabasePool,
count: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<M>, AppError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Menyimpan sejumlah record langsung ke database
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".