[][src]Struct debug_tree::TreeBuilder

pub struct TreeBuilder(_);

Reference wrapper for State

Methods

impl TreeBuilder[src]

pub fn new() -> TreeBuilder[src]

Returns a new TreeBuilder with an empty Tree.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();

pub fn set_indentation(&self, indent: usize)[src]

Sets the indentation level between tree branches. Aside from the first branch, indent is equal to the number of spaces a child branch is shifted from its parent.

Arguments

  • indent - The number of spaces used for indenting.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.set_indentation(4);

pub fn add_branch(&self, text: &str) -> ScopedBranch[src]

Adds a new branch with text, text and returns a ScopedBranch. When the returned ScopedBranch goes out of scope, (likely the end of the current block), or if its release() method is called, the tree will step back out of the added branch.

Arguments

  • text - A string slice to use as the newly added branch's text.

Examples

Exiting branch when end of scope is reached.

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
{
    let _branch = tree.add_branch("Branch"); // _branch enters scope
    // tree is now pointed inside new branch.
    tree.add_leaf("Child of Branch");
    // _branch leaves scope, tree moves up to parent branch.
}
tree.add_leaf("Sibling of Branch");
assert_eq!("\
Branch
└╼ Child of Branch
Sibling of Branch" , &tree.flush_string());

Using release() before out of scope.

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
{
    let mut branch = tree.add_branch("Branch"); // branch enters scope
    // tree is now pointed inside new branch.
    tree.add_leaf("Child of Branch");
    branch.release();
    tree.add_leaf("Sibling of Branch");
    // branch leaves scope, but no effect because its `release()` method has already been called
}
assert_eq!("\
Branch
└╼ Child of Branch
Sibling of Branch", &tree.flush_string());

pub fn enter_scoped(&self) -> ScopedBranch[src]

Adds a new branch with text, text and returns a ScopedBranch. When the returned ScopedBranch goes out of scope, (likely the end of the current block), or if its release() method is called, the tree tree will step back out of the added branch.

Arguments

  • text - A string slice to use as the newly added branch's text.

Examples

Stepping out of branch when end of scope is reached.

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
{
    tree.add_leaf("Branch");
    let _branch = tree.enter_scoped(); // _branch enters scope
    // tree is now pointed inside new branch.
    tree.add_leaf("Child of Branch");
    // _branch leaves scope, tree moves up to parent branch.
}
tree.add_leaf("Sibling of Branch");
assert_eq!("\
Branch
└╼ Child of Branch
Sibling of Branch", &tree.flush_string());

Using release() before out of scope.

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
{
    tree.add_leaf("Branch");
    let mut branch = tree.enter_scoped(); // branch enters scope
    // tree is now pointed inside new branch.
    tree.add_leaf("Child of Branch");
    branch.release();
    tree.add_leaf("Sibling of Branch");
    // branch leaves scope, but no effect because its `release()` method has already been called
}
assert_eq!("\
Branch
└╼ Child of Branch
Sibling of Branch", &tree.flush_string());

pub fn add_leaf(&self, text: &str)[src]

Adds a leaf to current branch with the given text, text.

Arguments

  • text - A string slice to use as the newly added leaf's text.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("New leaf");

pub fn enter(&self)[src]

Steps into a new child branch. Stepping out of the branch requires calling exit().

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Branch");
tree.enter();
tree.add_leaf("Child of Branch");
assert_eq!("\
Branch
└╼ Child of Branch", &tree.flush_string());

pub fn exit(&self) -> bool[src]

Exits the current branch, to the parent branch. If no parent branch exists, no action is taken

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Branch");
tree.enter();
tree.add_leaf("Child of Branch");
tree.exit();
tree.add_leaf("Sibling of Branch");
assert_eq!("\
Branch
└╼ Child of Branch
Sibling of Branch", &tree.flush_string());

pub fn depth(&self) -> usize[src]

Returns the depth of the current branch The initial depth when no branches have been adeed is 0.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
assert_eq!(0, tree.depth());
let _b = tree.add_branch("Branch");
assert_eq!(1, tree.depth());
let _b = tree.add_branch("Child branch");
assert_eq!(2, tree.depth());

pub fn peek_print(&self)[src]

Prints the tree without clearing.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Leaf");
tree.peek_print();
// Leaf
tree.peek_print();
// Leaf
// Leaf 2

pub fn flush_print(&self)[src]

Prints the tree and then clears it.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Leaf");
tree.flush_print();
// Leaf
tree.add_leaf("Leaf 2");
tree.flush_print();
// Leaf 2

pub fn peek_string(&self) -> String[src]

Returns the tree as a string without clearing the tree.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Leaf");
assert_eq!("Leaf", tree.peek_string());
tree.add_leaf("Leaf 2");
assert_eq!("Leaf\nLeaf 2", tree.peek_string());

pub fn flush_string(&self) -> String[src]

Returns the tree as a string and clears the tree.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Leaf");
assert_eq!("Leaf", tree.flush_string());
tree.add_leaf("Leaf 2");
assert_eq!("Leaf 2", tree.flush_string());

pub fn clear(&self)[src]

Clears the tree.

Example

use debug_tree::TreeBuilder;
let tree = TreeBuilder::new();
tree.add_leaf("Leaf");
assert_eq!("Leaf", tree.peek_string());
tree.clear();
assert_eq!("", tree.peek_string());

pub fn set_enabled(&self, enabled: bool)[src]

Sets the enabled state of the tree.

If not enabled, the tree will not be modified by adding leaves or branches. Additionally, if called using the add_... macros, arguments will not be processed. This is particularly useful for suppressing output in production, with very little overhead.

Example

#[macro_use]
use debug_tree::{TreeBuilder, add_leaf_to};
let mut tree = TreeBuilder::new();
tree.add_leaf("Leaf 1");
tree.set_enabled(false);
add_leaf_to!(tree, "Leaf 2");
tree.set_enabled(true);
add_leaf_to!(tree, "Leaf 3");
assert_eq!("Leaf 1\nLeaf 3", tree.peek_string());

pub fn is_enabled(&self) -> bool[src]

Returns the enabled state of the tree.

Example

use debug_tree::TreeBuilder;
let mut tree = TreeBuilder::new();
assert_eq!(true, tree.is_enabled());
tree.set_enabled(false);
assert_eq!(false, tree.is_enabled());

Trait Implementations

impl Clone for TreeBuilder[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for TreeBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]