Skip to content

Commit

Permalink
Add an example to use the auto id feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
clementwanjau committed Jul 8, 2024
1 parent 595fb19 commit cddd7dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/auto_node_id/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "auto_node_id"
version = "0.1.0"
edition = "2021"

[dependencies]
tree-ds = { path = "../../../tree-ds", features = ["auto_id"] }
21 changes: 21 additions & 0 deletions examples/auto_node_id/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use tree_ds::prelude::*;

fn main() {
let mut tree = Tree::<AutomatedId, &str>::new(Some("Sample Tree"));
let ceo_node = tree
.add_node(Node::new_with_auto_id(Some("CEO")), None)
.unwrap();
let _coo_node = tree
.add_node(Node::new_with_auto_id(Some("COO")), Some(&ceo_node))
.unwrap();
let _cto_node = tree
.add_node(Node::new_with_auto_id(Some("CTO")), Some(&ceo_node))
.unwrap();
let _cfo_node = tree
.add_node(Node::new_with_auto_id(Some("CFO")), Some(&ceo_node))
.unwrap();
let _cio_node = tree
.add_node(Node::new_with_auto_id(Some("CIO")), Some(&ceo_node))
.unwrap();
println!("{}", tree);
}

0 comments on commit cddd7dd

Please sign in to comment.