Macro ego_tree::tree [] [src]

macro_rules! tree {
    (@ $n:ident { }) => { ... };
    (@ $n:ident { $value:expr }) => { ... };
    (@ $n:ident { $value:expr, $($tail:tt)* }) => { ... };
    (@ $n:ident { $value:expr => $children:tt }) => { ... };
    (@ $n:ident { $value:expr => $children:tt, $($tail:tt)* }) => { ... };
    () => { ... };
    ($root:expr) => { ... };
    ($root:expr => { }) => { ... };
    ($root:expr => $children:tt) => { ... };
}

Creates a Tree from expressions.

With no arguments, it is equivalent to Tree::default.

#[macro_use]
extern crate ego_tree;
use ego_tree::Tree;

let tree: Tree<i32> = tree!();

With a single argument, it is equivalent to Tree::new.

let tree = tree!(0i32);

With a tree-like argument, a Tree is created, mutated, and returned.

let tree = tree! {
    "root" => {
        "child_a",
        "child_b" => {
            "grandchild_a",
            "grandchild_b",
        },
        "child_c",
    }
};

Note that nodes are inserted in the order they appear, which may not be the most efficient way of constructing the tree.

Additionally, after inserting the last node, it will travel all the way back up the tree, even when unnecessary.