pub struct DomNode(/* private fields */);Expand description
Based on https://docs.rs/rctree/latest/rctree/struct.Node.html
Implementations§
Source§impl DomNode
impl DomNode
Sourcepub fn new(kind: DomNodeKind) -> DomNode
pub fn new(kind: DomNodeKind) -> DomNode
Creates a new node
pub fn create_element(tag: impl Into<String>) -> DomNode
pub fn create_element_with_attributes( tag: impl Into<String>, attributes: HashMap<String, String>, ) -> DomNode
pub fn create_text(text: impl Into<String>) -> DomNode
pub fn get_attribute(&self, attribute: &str) -> Option<String>
pub fn set_attribute(&mut self, key: &str, value: &str)
Sourcepub fn downgrade(&self) -> WeakDomNode
pub fn downgrade(&self) -> WeakDomNode
Returns a weak referece to a node.
Sourcepub fn parent(&self) -> Option<DomNode>
pub fn parent(&self) -> Option<DomNode>
Returns a parent node, unless this node is the root of the tree.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn first_child(&self) -> Option<DomNode>
pub fn first_child(&self) -> Option<DomNode>
Returns a first child of this node, unless it has no child.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn last_child(&self) -> Option<DomNode>
pub fn last_child(&self) -> Option<DomNode>
Returns a last child of this node, unless it has no child.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn previous_sibling(&self) -> Option<DomNode>
pub fn previous_sibling(&self) -> Option<DomNode>
Returns the previous sibling of this node, unless it is a first child.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn next_sibling(&self) -> Option<DomNode>
pub fn next_sibling(&self) -> Option<DomNode>
Returns the next sibling of this node, unless it is a last child.
§Panics
Panics if the node is currently mutably borrowed.
pub fn kind(&self) -> Ref<'_, DomNodeKind>
pub fn kind_mut(&self) -> RefMut<'_, DomNodeKind>
Sourcepub fn ancestors(&self) -> Ancestors ⓘ
pub fn ancestors(&self) -> Ancestors ⓘ
Returns an iterator of nodes to this node and its ancestors.
Includes the current node.
Sourcepub fn preceding_siblings(&self) -> PrecedingSiblings ⓘ
pub fn preceding_siblings(&self) -> PrecedingSiblings ⓘ
Returns an iterator of nodes to this node and the siblings before it.
Includes the current node.
Sourcepub fn following_siblings(&self) -> FollowingSiblings ⓘ
pub fn following_siblings(&self) -> FollowingSiblings ⓘ
Returns an iterator of nodes to this node and the siblings after it.
Includes the current node.
Sourcepub fn children(&self) -> Children ⓘ
pub fn children(&self) -> Children ⓘ
Returns an iterator of nodes to this node’s children.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children nodes.
§Panics
Panics if the node is currently mutably borrowed.
Sourcepub fn descendants(&self) -> Descendants ⓘ
pub fn descendants(&self) -> Descendants ⓘ
Returns an iterator of nodes to this node and its descendants, in tree order.
Includes the current node.
Sourcepub fn traverse(&self) -> Traverse ⓘ
pub fn traverse(&self) -> Traverse ⓘ
Returns an iterator of nodes to this node and its descendants, in tree order.
Sourcepub fn sanitize_children(&mut self)
pub fn sanitize_children(&mut self)
Remove empty tags or invalid html in a way that makes sense
pub fn get_elements_by_tag_name(&self, tag: &str) -> Vec<DomNode>
pub fn get_element_by_id(&self, id: &str) -> Option<DomNode>
Sourcepub fn inner_text(&self) -> String
pub fn inner_text(&self) -> String
Returns the text content of this node and all its descendants.
Sourcepub fn detach(&self)
pub fn detach(&self)
Detaches a node from its parent and siblings. Children are not affected.
§Panics
Panics if the node or one of its adjoining nodes is currently borrowed.
Sourcepub fn append_child(&self, new_child: impl Into<IterableNodes>)
pub fn append_child(&self, new_child: impl Into<IterableNodes>)
Appends a new child to this node, after existing children.
§Panics
Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.
Sourcepub fn prepend(&self, new_child: DomNode)
pub fn prepend(&self, new_child: DomNode)
Prepends a new child to this node, before existing children.
§Panics
Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.
Sourcepub fn insert_after(&self, new_sibling: DomNode)
pub fn insert_after(&self, new_sibling: DomNode)
Inserts a new sibling after this node.
§Panics
Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.
Sourcepub fn insert_before(&self, new_sibling: DomNode)
pub fn insert_before(&self, new_sibling: DomNode)
Inserts a new sibling before this node.
§Panics
Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.
pub fn from_html(html: Html) -> Option<Self>
Trait Implementations§
Source§impl Clone for DomNode
Cloning a Node only increments a reference count. It does not copy the data.
impl Clone for DomNode
Cloning a Node only increments a reference count. It does not copy the data.