pub struct Tree { /* private fields */ }Expand description
The arena holding one document’s nodes, with the document at
Tree::root.
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn new(root_type: NodeType) -> Self
pub fn new(root_type: NodeType) -> Self
A tree holding only a fresh node of root_type, which becomes the
root.
Sourcepub fn add(&mut self, node: MdNode) -> NodeId
pub fn add(&mut self, node: MdNode) -> NodeId
Add an unlinked node to the arena and return its id: a slot
Tree::free_subtree gave back, when there is one.
Sourcepub fn free_subtree(&mut self, node: NodeId) -> Vec<NodeId>
pub fn free_subtree(&mut self, node: NodeId) -> Vec<NodeId>
Detach node and give its slot, and the slots of every node below
it, back to the arena for Tree::add to fill, dropping what each
held; answer the ids given back. Only for a node nothing will read
again: a slot given back takes the next node added, under the same
id. Iterative, since nesting is the input’s to choose.
Sourcepub fn new_node(&mut self, node_type: NodeType) -> NodeId
pub fn new_node(&mut self, node_type: NodeType) -> NodeId
Add an open, unlinked node of node_type.
pub fn get(&self, id: NodeId) -> &MdNode
pub fn get_mut(&mut self, id: NodeId) -> &mut MdNode
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many slots the arena holds, unlinked nodes’ and given-back ones included.
pub fn is_empty(&self) -> bool
Sourcepub fn append_child(&mut self, parent: NodeId, child: NodeId)
pub fn append_child(&mut self, parent: NodeId, child: NodeId)
Add child as the last child of parent, detaching it first.
Sourcepub fn prepend_child(&mut self, parent: NodeId, child: NodeId)
pub fn prepend_child(&mut self, parent: NodeId, child: NodeId)
Add child as the first child of parent, detaching it first.
Sourcepub fn insert_after(&mut self, node: NodeId, sibling: NodeId)
pub fn insert_after(&mut self, node: NodeId, sibling: NodeId)
Place sibling directly after node.
Sourcepub fn insert_before(&mut self, node: NodeId, sibling: NodeId)
pub fn insert_before(&mut self, node: NodeId, sibling: NodeId)
Place sibling directly before node.