pub trait HasFactory: Sized {
// Required method
fn factory() -> Factory<Self>;
}Expand description
A model with a factory.
Implemented by #[derive(Factory)], which needs Default — or by hand,
when the default row is not a sensible starting point:
ⓘ
impl HasFactory for User {
fn factory() -> Factory<Self> {
Factory::new(|i| User {
id: 0,
email: format!("user{i}@example.com"),
verified_at: None,
})
}
}Writing it by hand is often the better answer for a model with unique columns: it puts the sequence in one place instead of in every test.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".