pub struct Node { /* private fields */ }
Expand description
A node inside a DOM-like tree.
Implementations§
source§impl Node
impl Node
sourcepub fn as_element(&self) -> Option<&ElementData>
pub fn as_element(&self) -> Option<&ElementData>
If this node is an element, return a reference to element-specific data.
sourcepub fn as_text(&self) -> Option<&RefCell<String>>
pub fn as_text(&self) -> Option<&RefCell<String>>
If this node is a text node, return a reference to its contents.
sourcepub fn as_comment(&self) -> Option<&RefCell<String>>
pub fn as_comment(&self) -> Option<&RefCell<String>>
If this node is a comment, return a reference to its contents.
sourcepub fn as_doctype(&self) -> Option<&Doctype>
pub fn as_doctype(&self) -> Option<&Doctype>
If this node is a document, return a reference to doctype-specific data.
sourcepub fn as_document(&self) -> Option<&DocumentData>
pub fn as_document(&self) -> Option<&DocumentData>
If this node is a document, return a reference to document-specific data.
sourcepub fn parent(&self) -> Option<NodeRef>
pub fn parent(&self) -> Option<NodeRef>
Return a reference to the parent node, unless this node is the root of the tree.
sourcepub fn first_child(&self) -> Option<NodeRef>
pub fn first_child(&self) -> Option<NodeRef>
Return a reference to the first child of this node, unless it has no child.
sourcepub fn last_child(&self) -> Option<NodeRef>
pub fn last_child(&self) -> Option<NodeRef>
Return a reference to the last child of this node, unless it has no child.
sourcepub fn previous_sibling(&self) -> Option<NodeRef>
pub fn previous_sibling(&self) -> Option<NodeRef>
Return a reference to the previous sibling of this node, unless it is a first child.
sourcepub fn next_sibling(&self) -> Option<NodeRef>
pub fn next_sibling(&self) -> Option<NodeRef>
Return a reference to the next sibling of this node, unless it is a last child.
Trait Implementations§
source§impl Drop for Node
impl Drop for Node
Prevent implicit recursion when dropping nodes to avoid overflowing the stack.
The implicit drop is correct, but recursive. In the worst case (where no node has both a next sibling and a child), a tree of a few tens of thousands of nodes could cause a stack overflow.
This Drop
implementations makes sure the recursion does not happen.
Instead, it has an explicit Vec<Rc<Node>>
stack to traverse the subtree,
but only following Rc<Node>
references that are “unique”:
that have a strong reference count of 1.
Those are the nodes that would have been dropped recursively.
The stack holds ancestors of the current node rather than preceding siblings, on the assumption that large document trees are typically wider than deep.