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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// #############################################################################
// ################################### INPUT ###################################
// #############################################################################
use std::path::PathBuf;
#[derive(PartialEq,Debug)]
struct Foobar(
PathBuf,
PathBuf,
);
// #############################################################################
// ############################## IMPLEMENTATION ###############################
// #############################################################################
// impl_target
impl Foobar {
pub fn builder() -> FoobarBuilder {
<FoobarBuilder as ::core::default::Default>::default()
}
}
// struct_builder
#[derive(Default,)]
struct FoobarBuilder(
::macon::Building<PathBuf>,
::macon::Building<PathBuf>,
);
// impl_builder
impl FoobarBuilder {
// impl_builder / impl_builder_setters
pub fn set0<V0: Into<PathBuf>>(mut self, v0: V0) -> Self {
self.0 = ::macon::Building::Set(v0.into());
self
}
pub fn set1<V1: Into<PathBuf>>(mut self, v1: V1) -> Self {
self.1 = ::macon::Building::Set(v1.into());
self
}
// impl_builder / impl_builder_build
// impl_builder / impl_builder_build / impl_builder_build_from_scratch
pub fn build(self) -> Foobar {
let mut errors: ::std::vec::Vec<::std::string::String> = ::std::vec![];
if self.0.is_undefined() {
errors.push("Field 0 is missing".into());
}
if self.1.is_undefined() {
errors.push("Field 1 is missing".into());
}
if !errors.is_empty() {
panic!("{}", errors.join("\n"))
} else {
Foobar(
self.0.unwrap(),
self.1.unwrap(),
)
}
}
}
// impl_builder / impl_builder_from
impl ::core::convert::From<FoobarBuilder> for Foobar {
fn from(builder: FoobarBuilder) -> Self {
builder.build()
}
}
// #############################################################################
// ################################### TESTS ###################################
// #############################################################################
#[test]
fn builder_build_full() {
let built = Foobar::builder()
.set1("/tmp/builder_build.1")
.set0("/tmp/builder_build.0")
.build();
assert_eq!(
Foobar(
PathBuf::from("/tmp/builder_build.0"),
PathBuf::from("/tmp/builder_build.1"),
),
built,
);
}
#[test]
#[should_panic(expected = "Field 0 is missing")]
fn builder_build_missing() {
Foobar::builder()
.set1("/tmp/builder_build.002")
.build();
}
#[test]
fn builder_into_full() {
let built: Foobar = Foobar::builder()
.set0("/tmp/builder_into.0")
.set1("/tmp/builder_into.1")
.into();
assert_eq!(
Foobar(
PathBuf::from("/tmp/builder_into.0"),
PathBuf::from("/tmp/builder_into.1"),
),
built,
);
}
#[test]
#[should_panic(expected = "Field 1 is missing")]
fn builder_into_missing() {
Foobar::builder()
.set0("/tmp/builder_into.001")
.build();
}