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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
use std::collections::{HashMap, HashSet};
use buildstructor::buildstructor;
pub struct Collections {
names: HashSet<String>,
ages: HashMap<String, u64>,
addresses: Vec<String>,
}
#[buildstructor]
impl Collections {
#[builder]
fn new(
names: HashSet<String>,
ages: HashMap<String, u64>,
addresses: Vec<String>,
) -> Collections {
Self {
names,
ages,
addresses,
}
}
}
fn main() {
let collections = Collections::builder()
.name("Nandor".to_string())
.name("Nandor")
.name("Colin".to_string())
.names(HashSet::from(["Nadja", "Laszlo"].map(str::to_string)))
.age("Nandor".to_string(), 0)
.age("Nandor", 759)
.age("Colin".to_string(), 100)
.ages(HashMap::from(
[("Nadja", 650), ("Laszlo", 364)].map(|(k, v)| (k.to_string(), v)),
))
.address("Staten Island".to_string())
.address("Staten Island")
.addresses(Vec::from(["France", "Turkey"].map(str::to_string)))
.build();
assert_eq!(
collections.names,
HashSet::from(["Nandor", "Laszlo", "Nadja", "Colin"].map(str::to_string))
);
assert_eq!(
collections.ages,
HashMap::from(
[
("Nadja", 650),
("Laszlo", 364),
("Colin", 100),
("Nandor", 759)
]
.map(|(k, v)| (k.to_string(), v))
)
);
assert_eq!(
collections.addresses,
Vec::from(["Staten Island", "Staten Island", "France", "Turkey"].map(str::to_string))
);
}
|