-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sub_factory.rs
44 lines (37 loc) · 845 Bytes
/
sub_factory.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct File {
id: u16,
path: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
id: u16,
name: String,
file: File,
}
mod factory {
use crate::File;
use crate::User;
beaver::define! {
pub UserFactory (User) {
id -> |n| n,
name -> |n| format!("user-{}", n),
file -> |n| FileFactory::build(n),
}
}
beaver::define! {
pub FileFactory (File) {
id -> |n| n,
path -> |n| format!("path/to/file-{}", n),
}
}
}
fn main() {
use factory::UserFactory;
let user_factory = UserFactory::new();
let users = user_factory.build_list(10, |_| {});
for user in users {
println!("{:?}", user);
}
}