-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Implements this tree | ||
//! ``` | ||
//! 1 | ||
//! ├── 2 | ||
//! └── 3 | ||
//! ├── 4 | ||
//! └── 5 | ||
//! ``` | ||
use ego_tree::{tree, NodeMut, Tree}; | ||
|
||
fn main() { | ||
// Manual construction of the tree | ||
let mut tree: Tree<i32> = Tree::new(1); | ||
let mut root: NodeMut<i32> = tree.root_mut(); | ||
root.append(2); | ||
let mut child: NodeMut<i32> = root.append(3); | ||
child.append(4); | ||
child.append(5); | ||
println!("Manual:\n{tree}"); | ||
|
||
// Construction of the tree through the tree! macro | ||
let macro_tree: Tree<i32> = tree!(1 => {2, 3 => {4, 5}}); | ||
println!("Automated:\n{macro_tree}"); | ||
|
||
// Prooving equality | ||
assert_eq!(tree, macro_tree); | ||
} |