macro_rules! btree {
($val:expr, $l:expr, $r:expr) => { ... };
($val:expr, , $r:expr) => { ... };
($val:expr, $l:expr,) => { ... };
($val:expr) => { ... };
}Expand description
Short-hand for constructing Trees. btree! takes 3 arguments, the first being the
value of the root node, and the other two being child nodes. The last two arguments are
optional.
use gemla::tree::*;
use gemla::btree;
// A tree with two child nodes.
let t = btree!(1, btree!(2), btree!(3));
assert_eq!(t,
Tree::new(1,
Some(Box::new(Tree::new(2, None, None))),
Some(Box::new(Tree::new(3, None, None)))));
// A tree with only a left node.
let t_left = btree!(1, btree!(2),);
assert_eq!(t_left,
Tree::new(1,
Some(Box::new(Tree::new(2, None, None))),
None));
// A tree with only a right node.
let t_right = btree!(1, , btree!(3));
assert_eq!(t_right,
Tree::new(1,
None,
Some(Box::new(Tree::new(3, None, None)))));
// A tree with no child nodes.
let t_single = btree!(1);
assert_eq!(t_single,
Tree::new(1,
None,
None));