pub struct TreeRefMut<'a, 'b> {
pub id: TreeRefId,
pub tree: &'b mut Tree<'a>,
}
Expand description
A mutable reference to a node in the tree.
Fields§
§id: TreeRefId
A unique ID identifying the node in the tree.
tree: &'b mut Tree<'a>
The tree owning this node.
Implementations§
Source§impl<'a, 'b> TreeRefMut<'a, 'b>
impl<'a, 'b> TreeRefMut<'a, 'b>
pub fn id(&self) -> TreeRefId
pub fn as_ref(&self) -> TreeRef<'a, '_>
Sourcepub fn spanned_data(&mut self) -> &mut ParsedNode<'a>
pub fn spanned_data(&mut self) -> &mut ParsedNode<'a>
Get an mutable reference to the underlying ParsedNode
containing the Node
and the
location of the span of text where it was defined.
§Panics
Panics if the node does not exist in the tree (it could have been removed).
Sourcepub fn parent(&mut self) -> TreeRefMut<'a, '_>
pub fn parent(&mut self) -> TreeRefMut<'a, '_>
Get a reference to the parent of this node.
Sourcepub fn prev_sibling(&'b mut self) -> Option<Self>
pub fn prev_sibling(&'b mut self) -> Option<Self>
Get a reference to the previous sibling of this node.
Sourcepub fn next_sibling(&'b mut self) -> Option<Self>
pub fn next_sibling(&'b mut self) -> Option<Self>
Get a reference to the next sibling of this node.
Sourcepub fn set_text<T: Into<Cow<'a, str>>>(
&mut self,
new_text: T,
escaping: Escaping,
)
pub fn set_text<T: Into<Cow<'a, str>>>( &mut self, new_text: T, escaping: Escaping, )
Set the text of the TreeRef
while escaping the content using the provided Escaping
variant (if you are lazy, you can use Escaping::default
as a safe default).
Replaces all the children with the provided text if it is a Node::Element
.
Updates the text content if it is a Node::TemplateBlock(TemplateBlock::RawText(_))
.
Does nothing if the node is neither a Node::Element
nor a Node::TemplateBlock(TemplateBlock::RawText(_))
.
Sourcepub fn set_attr<A: Into<Cow<'a, str>>, B: Into<Cow<'a, str>>>(
&mut self,
key: A,
val: B,
escaping: Escaping,
)
pub fn set_attr<A: Into<Cow<'a, str>>, B: Into<Cow<'a, str>>>( &mut self, key: A, val: B, escaping: Escaping, )
Set the value of an attribute belonging to a Node::Element
.
The value of the attribute will be updated if it already exists or a new entry will be inserted.
The second argument should be ""
(an empty string) if the attribute has no value.
This method does nothing if not called on a Node::Element
.
Sourcepub fn remove_attr<'c, A: Into<Cow<'c, str>>>(&mut self, key: A)
pub fn remove_attr<'c, A: Into<Cow<'c, str>>>(&mut self, key: A)
Remove an attribute belonging to a Node::Element
.
This method does nothing if the attribute key does not exist.
Sourcepub fn replace_node(self, tree: &Tree<'a>)
pub fn replace_node(self, tree: &Tree<'a>)
Replace the current Node
with one or more Node
s of a Tree
.
This function consumes the TreeRefMut
to avoid using a node that was removed.
§Panics
This function panics if the node is not found in its parent children. If it happens, it is
a bug in pochoir-parser
not a bug in your code.
Sourcepub fn prepend_children(&mut self, tree: &Tree<'a>)
pub fn prepend_children(&mut self, tree: &Tree<'a>)
Sourcepub fn append_children(&mut self, tree: &Tree<'a>)
pub fn append_children(&mut self, tree: &Tree<'a>)
Sourcepub fn replace_node_owned(self, tree: &OwnedTree)
pub fn replace_node_owned(self, tree: &OwnedTree)
Replace the current Node
with one or more Node
s of a OwnedTree
.
This function consumes the TreeRefMut
to avoid using a node that was removed.
§Panics
This function panics if the node is not found in its parent children. If it happens, it is
a bug in pochoir-parser
not a bug in your code.
Sourcepub fn prepend_children_owned(&mut self, tree: &OwnedTree)
pub fn prepend_children_owned(&mut self, tree: &OwnedTree)
Sourcepub fn append_children_owned(&mut self, tree: &OwnedTree)
pub fn append_children_owned(&mut self, tree: &OwnedTree)
Sourcepub fn prepend_html<T: Into<Cow<'a, str>>>(
&mut self,
file_path: &str,
html: T,
) -> Result<()>
pub fn prepend_html<T: Into<Cow<'a, str>>>( &mut self, file_path: &str, html: T, ) -> Result<()>
Prepend HTML as children of the current TreeRefMut
.
§Errors
Returns an error if parsing the HTML failed.
Sourcepub fn append_html<T: Into<Cow<'a, str>>>(
&mut self,
file_path: &str,
html: T,
) -> Result<()>
pub fn append_html<T: Into<Cow<'a, str>>>( &mut self, file_path: &str, html: T, ) -> Result<()>
Append HTML as children of the current TreeRefMut
.
§Errors
Returns an error if parsing the HTML failed.
Sourcepub fn remove(self)
pub fn remove(self)
Remove the node from the tree.
This function consumes the TreeRefMut
to avoid using a node that was removed.
§Panics
This function panics if the node is not found in its parent children. If it happens, it is
a bug in pochoir-parser
not a bug in your code.