Skip to content

Commit

Permalink
Make minor adjustments to browse example (#98)
Browse files Browse the repository at this point in the history
## Description

This adds a total node count to the `async_browse` example and uses
human-readable output for [node
classes](https://reference.opcfoundation.org/Core/Part3/v104/docs/8.30#_Ref130971442)
instead of the underlying node class index.

Co-authored-by: Uwe Klotz <uwe.klotz@gmail.com>
  • Loading branch information
sgoll and uklotzde committed Apr 29, 2024
1 parent 6aafb51 commit d4ba335
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/async_browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ async fn main() -> anyhow::Result<()> {
return format!("{node_id}");
};

let info = format!("{}, {:?}", node.display_name().text(), node.node_class());
let info = format!("{}, {}", node.display_name().text(), node.node_class());

format!("{name} ({info}) -> {node_id}")
});

println!("{} nodes in total", hierarchy.node_count());

Ok(())
}

Expand Down Expand Up @@ -214,6 +216,10 @@ impl<T> TreeNode<T> {
root_node
}

fn node_count(&self) -> usize {
1 + self.children.values().map(Self::node_count).sum::<usize>()
}

fn pretty_print<FL>(&self, mut label: FL)
where
FL: FnMut(Option<&str>, &T) -> String,
Expand Down

0 comments on commit d4ba335

Please sign in to comment.