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
macro_rules! do_thing {
($name: ident => $($inner: tt)*) => {
mod $name {
use bauer::Builder;
#[derive(Builder)]
#[builder(
doc $($inner)*,
build_fn {
doc $($inner)*
},
error {
doc $($inner)*
}
)]
pub struct Struct {
#[builder(
doc(
/// Some documentation
)
)]
field: u8,
}
#[test]
fn build() {
let x = Struct::builder().field(0).build().unwrap();
assert_eq!(x.field, 0);
}
}
}
}
#[rustfmt::skip] // rustfmt really does not like this style of attributes in macro
macro_rules! tests {
($kind: literal in mod $module: ident $($unwrap: ident)?) => {
pub mod $module {
do_thing!(paren_comment => (
/// Some documentation
/// with multiple lines
));
do_thing!(brace_comment => {
/// Some documentation
/// with multiple lines
});
do_thing!(paren_attribute => (hidden));
do_thing!(brace_attribute => {hidden});
do_thing!(paren_comment_attribute => (
hidden
/// Some documentation
));
do_thing!(brace_comment_attribute => {
hidden
/// Some documentation
});
do_thing!(paren_comment_attribute_comma => (
hidden,
/// Some documentation
));
do_thing!(brace_comment_attribute_comma => {
hidden,
/// Some documentation
});
}
};
}
tests!("borrowed" in mod borrowed unwrap);
tests!("owned" in mod owned unwrap);
tests!("type-state" in mod type_state);