Struct TreeRefMut

Source
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>

Source

pub fn id(&self) -> TreeRefId

Source

pub fn as_ref(&self) -> TreeRef<'a, '_>

Source

pub fn data(&mut self) -> &mut Node<'a>

Get a mutable reference to the underlying Node.

§Panics

Panics if the node does not exist in the tree (it could have been removed).

Source

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).

Source

pub fn parent(&mut self) -> TreeRefMut<'a, '_>

Get a reference to the parent of this node.

Source

pub fn prev_sibling(&'b mut self) -> Option<Self>

Get a reference to the previous sibling of this node.

Source

pub fn next_sibling(&'b mut self) -> Option<Self>

Get a reference to the next sibling of this node.

Source

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(_)).

Source

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.

Source

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.

Source

pub fn replace_node(self, tree: &Tree<'a>)

Replace the current Node with one or more Nodes 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.

Source

pub fn prepend_children(&mut self, tree: &Tree<'a>)

Prepend the Nodes of a Tree to the list of children of the current node.

Source

pub fn append_children(&mut self, tree: &Tree<'a>)

Append the Nodes of a Tree to the list of children of the current node.

Source

pub fn replace_node_owned(self, tree: &OwnedTree)

Replace the current Node with one or more Nodes 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.

Source

pub fn prepend_children_owned(&mut self, tree: &OwnedTree)

Prepend the Nodes of a OwnedTree to the list of children of the current node.

Source

pub fn append_children_owned(&mut self, tree: &OwnedTree)

Append the Nodes of a OwnedTree to the list of children of the current node.

Source

pub fn replace_html<T: Into<Cow<'a, str>>>( self, file_path: &str, html: T, ) -> Result<()>

Replace the outer HTML of the TreeRefMut.

§Errors

Returns an error if parsing the HTML failed.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for TreeRefMut<'_, '_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TreeRefMut<'_, '_>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for TreeRefMut<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for TreeRefMut<'a, 'b>

§

impl<'a, 'b> Send for TreeRefMut<'a, 'b>

§

impl<'a, 'b> Sync for TreeRefMut<'a, 'b>

§

impl<'a, 'b> Unpin for TreeRefMut<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for TreeRefMut<'a, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.