workspacer_tree/
workspace_tree_node.rs1crate::ix!();
3
4#[derive(Debug)]
5pub struct WorkspaceTreeNode {
6 crate_name: String,
7 crate_version: Option<SemverVersion>,
8 crate_path: PathBuf,
9 children: Vec<WorkspaceTreeNode>,
10}
11
12impl WorkspaceTreeNode {
13 pub fn new(
15 crate_name: String,
16 crate_version: Option<SemverVersion>,
17 crate_path: PathBuf,
18 ) -> Self {
19 Self {
20 crate_name,
21 crate_version,
22 crate_path,
23 children: Vec::new(),
24 }
25 }
26
27 pub fn add_child(&mut self, child: WorkspaceTreeNode) {
29 self.children.push(child);
30 }
31
32 pub fn render_recursive(
35 &self,
36 level: usize,
37 show_version: bool,
38 show_path: bool,
39 out: &mut String,
40 ) {
41 let indent = " ".repeat(level);
43
44 let mut line = format!("{}{}", indent, self.crate_name);
46
47 if show_version {
48 if let Some(ref v) = self.crate_version {
49 line.push_str(&format!(" (v{})", v));
50 }
51 }
52
53 if show_path {
54 line.push_str(&format!(" [{}]", self.crate_path.display()));
55 }
56
57 out.push_str(&line);
58 out.push('\n');
59
60 for child in &self.children {
62 child.render_recursive(level + 1, show_version, show_path, out);
63 }
64 }
65}