Skip to main content

write_tree_safe

Function write_tree_safe 

Source
pub fn write_tree_safe<W: Write>(
    out: &mut W,
    tree: &BTreeMap<String, Box<Tree>>,
    depth: usize,
    max_depth: usize,
) -> Result<()>
Expand description

Writes the tree with indentation based on depth (SAFE RECURSIVE VERSION)

Recursive like write_tree, but a tree deeper than max_depth ends with an error of kind InvalidInput instead of a stack overflow. The lines up to that depth are written. The cost of the depth check is measured in the benchmarks (README, section Benchmarks).

ยงArguments

  • out - Where the lines go
  • tree - The tree to write
  • depth - Current depth level for indentation
  • max_depth - Maximum allowed recursion depth (typical: 1000-5000)