Lines Matching full:tree
26 /// Returns a new `TreeBuilder` with an empty `Tree`.
32 /// let tree = TreeBuilder::new();
46 /// let tree = TreeBuilder::new();
48 /// add_branch_to!(tree, "1");
50 /// add_branch_to!(tree, "1.1");
51 /// add_leaf_to!(tree, "1.1.1");
52 /// add_leaf_to!(tree, "1.1.2");
54 /// add_leaf_to!(tree, "1.2");
56 /// add_leaf_to!(tree, "2");
57 /// tree.set_config_override(TreeConfig::new()
60 /// tree.peek_print();
67 /// ╰╼ 2" , &tree.string());
87 /// let tree = TreeBuilder::new();
89 /// add_branch_to!(tree, "1");
91 /// add_branch_to!(tree, "1.1");
92 /// add_leaf_to!(tree, "1.1.1");
93 /// add_leaf_to!(tree, "1.1.2");
95 /// add_leaf_to!(tree, "1.2");
97 /// add_leaf_to!(tree, "2");
98 /// tree.update_config_override(|x|{
103 /// tree.peek_print();
110 /// ╰─╼ 2" , &tree.string());
138 /// or if its `release()` method is called, the tree will step back out of the added branch.
148 /// let tree = TreeBuilder::new();
150 /// let _branch = tree.add_branch("Branch"); // _branch enters scope
151 /// // tree is now pointed inside new branch.
152 /// tree.add_leaf("Child of Branch");
153 /// // _branch leaves scope, tree moves up to parent branch.
155 /// tree.add_leaf("Sibling of Branch");
159 /// Sibling of Branch" , &tree.string());
165 /// let tree = TreeBuilder::new();
167 /// let mut branch = tree.add_branch("Branch"); // branch enters scope
168 /// // tree is now pointed inside new branch.
169 /// tree.add_leaf("Child of Branch");
171 /// tree.add_leaf("Sibling of Branch");
177 /// Sibling of Branch", &tree.string());
186 … /// or if its `release()` method is called, the tree tree will step back out of the added branch.
196 /// let tree = TreeBuilder::new();
198 /// tree.add_leaf("Branch");
199 /// let _branch = tree.enter_scoped(); // _branch enters scope
200 /// // tree is now pointed inside new branch.
201 /// tree.add_leaf("Child of Branch");
202 /// // _branch leaves scope, tree moves up to parent branch.
204 /// tree.add_leaf("Sibling of Branch");
208 /// Sibling of Branch", &tree.string());
214 /// let tree = TreeBuilder::new();
216 /// tree.add_leaf("Branch");
217 /// let mut branch = tree.enter_scoped(); // branch enters scope
218 /// // tree is now pointed inside new branch.
219 /// tree.add_leaf("Child of Branch");
221 /// tree.add_leaf("Sibling of Branch");
227 /// Sibling of Branch", &tree.string());
246 /// let tree = TreeBuilder::new();
247 /// tree.add_leaf("New leaf");
262 /// let tree = TreeBuilder::new();
263 /// tree.add_leaf("Branch");
264 /// tree.enter();
265 /// tree.add_leaf("Child of Branch");
268 /// └╼ Child of Branch", &tree.string());
284 /// let tree = TreeBuilder::new();
285 /// tree.add_leaf("Branch");
286 /// tree.enter();
287 /// tree.add_leaf("Child of Branch");
288 /// tree.exit();
289 /// tree.add_leaf("Sibling of Branch");
293 /// Sibling of Branch", &tree.string());
311 /// let tree = TreeBuilder::new();
312 /// assert_eq!(0, tree.depth());
313 /// let _b = tree.add_branch("Branch");
314 /// assert_eq!(1, tree.depth());
315 /// let _b = tree.add_branch("Child branch");
316 /// assert_eq!(2, tree.depth());
322 /// Prints the tree without clearing.
328 /// let tree = TreeBuilder::new();
329 /// tree.add_leaf("Leaf");
330 /// tree.peek_print();
332 /// tree.peek_print();
340 /// Prints the tree and then clears it.
346 /// let tree = TreeBuilder::new();
347 /// tree.add_leaf("Leaf");
348 /// tree.print();
350 /// tree.add_leaf("Leaf 2");
351 /// tree.print();
358 /// Returns the tree as a string without clearing the tree.
364 /// let tree = TreeBuilder::new();
365 /// tree.add_leaf("Leaf");
366 /// assert_eq!("Leaf", tree.peek_string());
367 /// tree.add_leaf("Leaf 2");
368 /// assert_eq!("Leaf\nLeaf 2", tree.peek_string());
374 /// Returns the tree as a string and clears the tree.
380 /// let tree = TreeBuilder::new();
381 /// tree.add_leaf("Leaf");
382 /// assert_eq!("Leaf", tree.string());
383 /// tree.add_leaf("Leaf 2");
384 /// assert_eq!("Leaf 2", tree.string());
390 /// Writes the tree to file without clearing.
398 /// let tree = TreeBuilder::new();
400 /// tree.add_leaf("Leaf");
401 /// assert_eq!(tree.peek_string(), "Leaf");
402 /// tree.peek_write("test_out/peek_write.txt");
404 /// assert_eq!(tree.peek_string(), "Leaf");
411 /// Writes the tree to file without clearing.
419 /// let tree = TreeBuilder::new();
421 /// tree.add_leaf("Leaf");
422 /// assert_eq!(tree.peek_string(), "Leaf");
423 /// tree.write("test_out/write.txt");
425 /// assert_eq!(tree.peek_string(), "");
432 /// Clears the tree.
438 /// let tree = TreeBuilder::new();
439 /// tree.add_leaf("Leaf");
440 /// assert_eq!("Leaf", tree.peek_string());
441 /// tree.clear();
442 /// assert_eq!("", tree.peek_string());
448 /// Sets the enabled state of the tree.
450 /// If not enabled, the tree will not be modified by adding leaves or branches.
458 /// let mut tree = TreeBuilder::new();
459 /// tree.add_leaf("Leaf 1");
460 /// tree.set_enabled(false);
461 /// add_leaf_to!(tree, "Leaf 2");
462 /// tree.set_enabled(true);
463 /// add_leaf_to!(tree, "Leaf 3");
464 /// assert_eq!("Leaf 1\nLeaf 3", tree.peek_string());
470 /// Returns the enabled state of the tree.
475 /// let mut tree = TreeBuilder::new();
476 /// assert_eq!(true, tree.is_enabled());
477 /// tree.set_enabled(false);
478 /// assert_eq!(false, tree.is_enabled());
519 /// Sets the enabled state of the tree.
522 /// * `name` - The tree name
530 let tree = TreeBuilder::new(); in set_enabled() localVariable
531 tree.set_enabled(enabled); in set_enabled()
532 map.insert(name.as_ref().to_string(), tree); in set_enabled()
541 /// Check if the named tree is enabled and exists
542 /// This does not create a new tree if non-existent
545 /// * `tree_name` - The tree name
552 /// Returns the tree
553 /// If there is no tree then one is created and then returned.
554 pub fn tree<T: AsTree>(tree: T) -> TreeBuilder { in tree() function
555 tree.as_tree() in tree()
558 /// Returns the tree named `name`
559 /// If there is no tree named `name` then one is created and then returned.
560 pub fn is_tree_enabled<T: AsTree>(tree: &T) -> bool { in is_tree_enabled()
561 tree.is_tree_enabled() in is_tree_enabled()
564 /// Calls [clear](TreeBuilder::clear) for the tree named `name`
565 /// If there is no tree named `name` then one is created
570 /// Returns [string](TreeBuilder::string) for the tree named `name`
571 /// If there is no tree named `name` then one is created
576 /// Returns [peek_string](TreeBuilder::peek_string) for the tree named `name`
577 /// If there is no tree named `name` then one is created
582 /// Calls [print](TreeBuilder::print) for the tree named `name`
583 /// If there is no tree named `name` then one is created
588 /// Calls [peek_print](TreeBuilder::peek_print) for the tree named `name`
589 /// If there is no tree named `name` then one is created
594 /// Calls [write](TreeBuilder::write) for the tree named `name`
595 /// If there is no tree named `name` then one is created
600 /// Calls [peek_print](TreeBuilder::peek_print) for the tree named `name`
601 /// If there is no tree named `name` then one is created
606 /// Adds a leaf to given tree with the given text and formatting arguments
609 /// * `tree` - The tree that the leaf should be added to
618 /// let tree = TreeBuilder::new();
619 /// add_leaf_to!(tree, "A {} leaf", "new");
620 /// assert_eq!("A new leaf", &tree.peek_string());
625 ($tree:expr, $($arg:tt)*) => (if $crate::is_tree_enabled(&$tree) {
627 $tree.as_tree().add_leaf(&format!($($arg)*))
631 /// Adds a leaf to given tree with the given `value` argument
634 /// * `tree` - The tree that the leaf should be added to
643 /// let tree = TreeBuilder::new();
644 /// let value = add_leaf_value_to!(tree, 5 * 4 * 3 * 2);
646 /// assert_eq!("120", &tree.peek_string());
651 ($tree:expr, $value:expr) => {{
653 if $crate::is_tree_enabled(&$tree) {
655 $tree.as_tree().add_leaf(&format!("{}", &v));
661 /// Adds a scoped branch to given tree with the given text and formatting arguments
665 /// * `tree` - The tree that the leaf should be added to
674 /// let tree = TreeBuilder::new();
676 /// add_branch_to!(tree, "New {}", "Branch"); // _branch enters scope
677 /// // tree is now pointed inside new branch.
678 /// add_leaf_to!(tree, "Child of {}", "Branch");
679 /// // Block ends, so tree exits the current branch.
681 /// add_leaf_to!(tree, "Sibling of {}", "Branch");
685 /// Sibling of Branch" , &tree.string());
690 ($tree:expr) => {
691 let _debug_tree_branch = if $crate::is_tree_enabled(&$tree) {
693 $tree.as_tree().enter_scoped()
698 ($tree:expr, $($arg:tt)*) => {
699 let _debug_tree_branch = if $crate::is_tree_enabled(&$tree) {
701 $tree.as_tree().add_branch(&format!($($arg)*))
708 /// Calls `function` with argument, `tree`, at the end of the current scope
709 /// The function will only be executed if the tree is enabled when this macro is called
723 ($tree:expr, $function:expr) => {
726 if $tree.as_tree().is_enabled() {
727 $crate::defer::DeferredFn::new($tree.as_tree(), $function)
735 /// Calls [print](TreeBuilder::print) on `tree` at the end of the current scope.
736 /// The function will only be executed if the tree is enabled when this macro is called
744 ($tree:expr) => {
745 $crate::defer!($tree, |x| {
751 /// Calls [peek_print](TreeBuilder::peek_print) on `tree` at the end of the current scope.
752 /// The function will only be executed if the tree is enabled when this macro is called
760 ($tree:expr) => {
761 $crate::defer!($tree, |x| {
767 /// Calls [write](TreeBuilder::write) on `tree` at the end of the current scope.
768 /// The function will only be executed if the tree is enabled when this macro is called
771 ($tree:expr, $path:expr) => {
772 $crate::defer!($tree, |x| {
787 /// Calls [peek_write](TreeBuilder::peek_write) on `tree` at the end of the current scope.
788 /// The function will only be executed if the tree is enabled when this macro is called
791 ($tree:expr, $path:expr) => {
792 $crate::defer!($tree, |x| {