workspacer_tree/
workspace_dependency_tree.rs

1// ---------------- [ File: workspacer-tree/src/workspace_dependency_tree.rs ]
2crate::ix!();
3
4#[derive(Debug)]
5pub struct WorkspaceDependencyTree {
6    // The top-level crates with no incoming edges (roots).
7    // Not public; we’ll provide only internal constructor & printing.
8    roots: Vec<WorkspaceTreeNode>,
9}
10
11impl WorkspaceDependencyTree {
12    /// Internal constructor for the final tree.
13    pub fn new(roots: Vec<WorkspaceTreeNode>) -> Self {
14        Self { roots }
15    }
16
17    /// Helper for checking whether we’re empty (no crates).
18    pub fn is_empty(&self) -> bool {
19        self.roots.is_empty()
20    }
21
22    /// Render the entire forest as a string.  
23    /// `show_version`, `show_path` => whether to display version/path in output.
24    pub fn render(
25        &self,
26        show_version: bool,
27        show_path: bool,
28    ) -> String {
29        if self.is_empty() {
30            return "(no crates in workspace)".to_string();
31        }
32
33        let mut out = String::new();
34        for (i, root) in self.roots.iter().enumerate() {
35            // Indentation starts at level=0:
36            root.render_recursive(0, show_version, show_path, &mut out);
37            if i + 1 < self.roots.len() {
38                out.push('\n'); // blank line between top-level roots
39            }
40        }
41        out
42    }
43}