write_tree

Macro write_tree 

Source
macro_rules! write_tree {
    ($f:expr, $tree:expr $(,)?) => { ... };
    ($f:expr, $tree:expr, $style:expr $(,)?) => { ... };
}
Expand description

Writes a type that implements DisplayTree to a buffer as a tree.

A Style can be passed as the second argument to customize the way the tree is formatted.

§Examples

use display_tree::write_tree;

#[derive(display_tree::DisplayTree)]
struct Tree;

let mut buf = Vec::new();
write_tree!(&mut buf, Tree);

assert_eq!(&buf, "Tree".as_bytes());

Specifying a style:

use display_tree::{write_tree, CharSet, Style, StyleBuilder};

#[derive(display_tree::DisplayTree)]
struct Tree {
    a: i32,
    b: bool,
}

let mut buf = Vec::new();
write_tree!(
    &mut buf,
    Tree { a: 1, b: true },
    Style::default().char_set(CharSet::SINGLE_LINE_CURVED)
);

assert_eq!(
    &buf,
    "Tree\n\
     ├── 1\n\
     ╰── true"
        .as_bytes()
);