Skip to content

Commit 95aaf8b

Browse files
committed
provide examples
1 parent 8f4f80e commit 95aaf8b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/simple_tree.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Implements this tree
2+
//! ```
3+
//! 1
4+
//! ├── 2
5+
//! └── 3
6+
//! ├── 4
7+
//! └── 5
8+
//! ```
9+
10+
use ego_tree::{tree, NodeMut, Tree};
11+
12+
fn main() {
13+
// Manual construction of the tree
14+
let mut tree: Tree<i32> = Tree::new(1);
15+
let mut root: NodeMut<i32> = tree.root_mut();
16+
root.append(2);
17+
let mut child: NodeMut<i32> = root.append(3);
18+
child.append(4);
19+
child.append(5);
20+
println!("Manual:\n{tree}");
21+
22+
// Construction of the tree through the tree! macro
23+
let macro_tree: Tree<i32> = tree!(1 => {2, 3 => {4, 5}});
24+
println!("Automated:\n{macro_tree}");
25+
26+
// Prooving equality
27+
assert_eq!(tree, macro_tree);
28+
}

0 commit comments

Comments
 (0)