Trait LogTree

Source
pub trait LogTree: Sized {
    // Required method
    fn add_node(&self, lvl: u8) -> Option<(String, Childs<'_, Self>)>;

    // Provided methods
    fn decorators(&self, lvl: u8) -> [&str; 4] { ... }
    fn fmt_tree(&self) -> String { ... }
    fn fmt_tree_node(&self, is_last: bool) -> String { ... }
}

Required Methods§

Source

fn add_node(&self, lvl: u8) -> Option<(String, Childs<'_, Self>)>

Add a node to the tree.

  • Returns None if the node should not be added.
  • Returns Some((key, childs)) if the node should be added.
  • where childs can be empty, if the node is a leaf node.

The lvl parameter is the depth of the node in the tree.

Provided Methods§

Source

fn decorators(&self, lvl: u8) -> [&str; 4]

Decorators is an array of 4 strings, used to decorate the tree.

Source

fn fmt_tree(&self) -> String

format the tree, and return the formatted string.

Examples found in repository?
examples/basic.rs (line 25)
19fn main() {
20    let tree = t!(
21        A1,
22        t!(B1, t!(C1,), t!(C2,)),
23        t!(B2, t!(C1, t!(D1,), t!(D2,)))
24    );
25    println!("{}", tree.fmt_tree());
26}
Source

fn fmt_tree_node(&self, is_last: bool) -> String

Same as fmt_tree, but return the formatted string as child of tree.

Examples found in repository?
examples/pwd.rs (line 41)
38fn main() {
39    let path = env::current_dir().unwrap().to_string_lossy().to_string();
40    let tree = DirTree { path, is_dir: true };
41    println!("{}", tree.fmt_tree_node(true));
42}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§