-
Notifications
You must be signed in to change notification settings - Fork 1
/
configuration_template_visitors_nesting.rs
66 lines (60 loc) · 1.41 KB
/
configuration_template_visitors_nesting.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
macro_rules! visit_base {
($length:literal, $($contents:expr)*) => {
fn list_assets() -> String {
let root_depth = 0;
[$($contents(root_depth),)*].join("")
}
};
}
macro_rules! visit_folder {
($name:literal, $id:ident, $($contents:expr)*) => {{
fn list_folder(depth: usize) -> String {
let name = $name;
[
indent_line(depth, &format!("{name}/")),
$($contents(depth + 1),)*
]
.join("")
}
list_folder
}};
}
fn indent_line(depth: usize, contents: &str) -> String {
let indentation = " ".repeat(depth);
format!("{indentation}{contents}\n")
}
macro_rules! visit_file {
($name:literal, $id:ident, $index:literal, $relative_path:literal, $absolute_path:literal) => {{
fn list_file(depth: usize) -> String {
indent_line(depth, $name)
}
list_file
}};
}
#[iftree::include_file_tree(
"
paths = '/examples/assets/**'
[[template]]
visit_base = 'visit_base'
visit_folder = 'visit_folder'
visit_file = 'visit_file'
"
)]
pub struct Asset;
fn main() {
assert_eq!(
list_assets(),
"examples/
assets/
.env
configuration/
menu.json
translations.csv
credits.md
world/
levels/
tutorial.json
physical_constants.json
",
);
}