pub struct AsTree<'a, T: DisplayTree> { /* private fields */ }
Expand description
A helper struct for formatting a type that implements DisplayTree
.
AsTree
stores a reference to the type to format. It implements
std::fmt::Display
, so it can be used in println!
, format!
,
etc…
§Styling
AsTree
controls the way a tree is styled when it is formatted. The style
can be customized using builder methods. See Style
for the different
aspects that can be customized.
Note: StyleBuilder
must be in scope to use the builder methods.
Note: Some styling options use ANSI escape codes and therefore will only
work where they are supported. See TextStyle
for more information.
§Examples
use display_tree::{AsTree, DisplayTree};
#[derive(DisplayTree)]
struct Tree {
a: i32,
b: i32,
}
let tree = Tree { a: 1, b: 2 };
assert_eq!(
format!("{}", AsTree::new(&tree)),
"Tree\n\
├── 1\n\
└── 2"
);
Specifying a style:
use display_tree::{AsTree, CharSet, DisplayTree, StyleBuilder};
#[derive(DisplayTree)]
struct Tree {
a: i32,
b: i32,
}
let tree = Tree { a: 1, b: 2 };
assert_eq!(
format!("{}", AsTree::new(&tree).char_set(CharSet::DOUBLE_LINE)),
"Tree\n\
╠══ 1\n\
╚══ 2"
);
Implementations§
Source§impl<'a, T: DisplayTree> AsTree<'a, T>
impl<'a, T: DisplayTree> AsTree<'a, T>
Sourcepub fn new(tree: &'a T) -> Self
pub fn new(tree: &'a T) -> Self
Creates a wrapper around a type that implements DisplayTree
,
allowing it to be formatted.
§Examples
use display_tree::{AsTree, DisplayTree};
#[derive(DisplayTree)]
struct Tree;
let as_tree = AsTree::new(&Tree);
Sourcepub fn with_style(tree: &'a T, style: Style) -> Self
pub fn with_style(tree: &'a T, style: Style) -> Self
Creates a wrapper around a type that implements DisplayTree
,
allowing it to be formatted with the given style.
§Examples
use display_tree::{AsTree, DisplayTree, Style};
#[derive(DisplayTree)]
struct Tree;
let as_styled_tree = AsTree::with_style(&Tree, Style::default());
Trait Implementations§
Source§impl<'a, T: DisplayTree> Display for AsTree<'a, T>
impl<'a, T: DisplayTree> Display for AsTree<'a, T>
Source§impl<'a, T: DisplayTree> StyleBuilder for AsTree<'a, T>
impl<'a, T: DisplayTree> StyleBuilder for AsTree<'a, T>
Source§fn indentation(self, indentation: u32) -> Self
fn indentation(self, indentation: u32) -> Self
Source§fn leaf_style(self, style: TextStyle) -> Self
fn leaf_style(self, style: TextStyle) -> Self
TextStyle
for more
information.Source§fn branch_style(self, style: TextStyle) -> Self
fn branch_style(self, style: TextStyle) -> Self
TextStyle
for more
information.Source§fn leaf_color(self, color: Color) -> Self
fn leaf_color(self, color: Color) -> Self
Color
for more
information.Source§fn leaf_background_color(self, color: Color) -> Self
fn leaf_background_color(self, color: Color) -> Self
Color
for
more information.Source§fn bold_leaves(self) -> Self
fn bold_leaves(self) -> Self
Source§fn faint_leaves(self) -> Self
fn faint_leaves(self) -> Self
Source§fn italic_leaves(self) -> Self
fn italic_leaves(self) -> Self
Source§fn underlined_leaves(self) -> Self
fn underlined_leaves(self) -> Self
Source§fn strikethrough_leaves(self) -> Self
fn strikethrough_leaves(self) -> Self
Source§fn branch_color(self, color: Color) -> Self
fn branch_color(self, color: Color) -> Self
Color
for more
information.Source§fn branch_background_color(self, color: Color) -> Self
fn branch_background_color(self, color: Color) -> Self
Color
for
more information.