tree_macro/
tree-macro.rs

1use indextree::{macros::tree, Arena};
2
3fn main() {
4    let mut arena = Arena::new();
5
6    // It works with existing nodes
7    let root_node = arena.new_node("my root node");
8    tree!(
9        &mut arena,
10        root_node => {
11            "1",
12            "2" => {
13                "2_1" => { "2_1_1" },
14                "2_2",
15            },
16            "3" => {},
17        }
18    );
19
20    println!("{}", root_node.debug_pretty_print(&arena));
21
22    // It can also create a root node for you!
23    let root_node = tree!(
24        &mut arena,
25        "my root node, but automagically created" => {
26            "1",
27            "2" => {
28                "2_1" => { "2_1_1" },
29                "2_2",
30            },
31            "3",
32        }
33    );
34
35    println!("{}", root_node.debug_pretty_print(&arena));
36}