TreeNodeOps

Struct TreeNodeOps 

Source
pub struct TreeNodeOps {}

Implementations§

Source§

impl TreeNodeOps

Source

pub fn text_of(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> StrTendril

Collects all text content of a node and its descendants.

§Arguments
  • nodes: a reference to a vector of TreeNodes.
  • id: NodeId of the element to get the text content from.

This function will traverse the tree and collect all text content from the node and its descendants. It will ignore any nodes that are not Elements or Texts.

The function returns a StrTendril containing all collected text content.

Source

pub fn normalized_char_count(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> usize

Traverses the tree and counts all text content of a node and its descendants, but only counting each sequence of whitespace as a single character.

§Arguments
  • nodes: a reference to a vector of TreeNodes.
  • id: NodeId of the element to get the text content from.

This function will traverse the tree and count all text content from the node and its descendants.

It has an advantage over node.text().split_whitespace().count() because it doesn’t need to collect and consume the text content.

§Returns

The number of characters that would be in the text content if it were normalized, where normalization means treating any sequence of whitespace characters as a single space.

Source

pub fn immediate_text_of( nodes: Ref<'_, Vec<TreeNode>>, id: NodeId, ) -> StrTendril

Returns the text of the node without its descendants.

Source

pub fn last_sibling_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>

Gets the last sibling node of a node by id.

This function walks through sibling nodes from the given node until there are no more sibling nodes. It returns the last sibling node id it found.

Source

pub fn next_element_sibling_of( nodes: &[TreeNode], id: &NodeId, ) -> Option<NodeId>

Returns the next sibling id, that is an NodeData::Element of the selected node.

Source

pub fn prev_element_sibling_of( nodes: &[TreeNode], id: &NodeId, ) -> Option<NodeId>

Returns the previous sibling id, that is an NodeData::Element of the selected node.

Source

pub fn first_element_child_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>

Returns the first child id, that is an NodeData::Element of the selected node.

Source

pub fn is_valid_node_id(nodes: &[TreeNode], id: &NodeId) -> bool

Checks if the given node id is valid in the tree.

Source§

impl TreeNodeOps

Source

pub fn create_node(nodes: &mut Vec<TreeNode>, data: NodeData) -> NodeId

Creates a new node with the given data.

Source

pub fn append_child_data_of( nodes: &mut Vec<TreeNode>, id: &NodeId, data: NodeData, )

Creates a new element from data and appends it to a node by id

Source

pub fn append_child_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )

Appends a child node by new_child_id to a node by id. new_child_id must exist in the tree.

Source

pub fn prepend_child_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )

Prepend a child node by new_child_id to a node by id. new_child_id must exist in the tree.

Source

pub fn insert_before_of( nodes: &mut [TreeNode], id: &NodeId, new_sibling_id: &NodeId, )

Append a sibling node in the tree before the given node.

Source

pub fn insert_after_of( nodes: &mut [TreeNode], id: &NodeId, new_sibling_id: &NodeId, )

Append a sibling node in the tree after the given node.

Source

pub fn insert_siblings_before( nodes: &mut [TreeNode], id: &NodeId, new_node_id: &NodeId, )

Inserts a node and it’s siblings by id before the selected node.

Source

pub fn insert_siblings_after( nodes: &mut [TreeNode], id: &NodeId, new_node_id: &NodeId, )

Inserts a node and it’s siblings by id after the selected node.

Source

pub fn append_children_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )

Appends another node and it’s siblings to the selected node.

Source

pub fn prepend_children_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )

Prepend another node and it’s siblings to the selected node.

Source

pub fn remove_from_parent(nodes: &mut [TreeNode], id: &NodeId)

Remove a node from the its parent by id. The node remains in the tree. It is possible to assign it to another node in the tree after this operation.

Source

pub fn reparent_children_of( nodes: &mut [TreeNode], id: &NodeId, new_parent_id: Option<NodeId>, )

Changes the parent of children nodes of a node.

Source

pub fn set_text<T>(nodes: &mut Vec<TreeNode>, id: &NodeId, text: T)
where T: Into<StrTendril>,

Parses given text and sets its contents to the selected node. This operation replaces any contents of the selected node with the given text.

Auto Trait Implementations§

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.