Struct AsTree

Source
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>

Source

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);
Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: DisplayTree> StyleBuilder for AsTree<'a, T>

Source§

fn char_set(self, char_set: CharSet) -> Self

Sets the CharSet making up the branches of the tree. Read more
Source§

fn indentation(self, indentation: u32) -> Self

Sets the indentation of each node. Read more
Source§

fn leaf_style(self, style: TextStyle) -> Self

Sets the style of the leaves of the tree. See TextStyle for more information.
Source§

fn branch_style(self, style: TextStyle) -> Self

Sets the style of the branches of the tre. See TextStyle for more information.
Source§

fn leaf_color(self, color: Color) -> Self

Sets the color of the leaves of the tree. See Color for more information.
Source§

fn leaf_background_color(self, color: Color) -> Self

Sets the background color of the leaves of the tree. See Color for more information.
Source§

fn bold_leaves(self) -> Self

Renders the leaves as bold.
Source§

fn faint_leaves(self) -> Self

Decreases the intensity of the leaves.
Source§

fn italic_leaves(self) -> Self

Italicises the leaves.
Source§

fn underlined_leaves(self) -> Self

Underlines the leaves.
Source§

fn strikethrough_leaves(self) -> Self

Causes the leaves to be crossed-out.
Source§

fn branch_color(self, color: Color) -> Self

Sets the color of the branches of the tree. See Color for more information.
Source§

fn branch_background_color(self, color: Color) -> Self

Sets the background color of the branches of the tree. See Color for more information.
Source§

fn bold_branches(self) -> Self

Renders the branches as bold.
Source§

fn faint_branches(self) -> Self

Decreases the intensity of the branches.

Auto Trait Implementations§

§

impl<'a, T> Freeze for AsTree<'a, T>

§

impl<'a, T> RefUnwindSafe for AsTree<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for AsTree<'a, T>
where T: Sync,

§

impl<'a, T> Sync for AsTree<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for AsTree<'a, T>

§

impl<'a, T> UnwindSafe for AsTree<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.