pub struct Tree<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Tree<'a>
impl<'a> Tree<'a>
pub fn file_path(&self) -> &Path
pub fn next_id(&self) -> TreeRefId
Sourcepub fn insert(&mut self, parent: TreeRefId, data: ParsedNode<'a>) -> TreeRefId
pub fn insert(&mut self, parent: TreeRefId, data: ParsedNode<'a>) -> TreeRefId
Insert a new node in the tree as a child of parent
.
§Panics
This function panics if the provided parent ID does not exist in the tree. It may happen if the ID is wrong, does not exist in the tree or if the node having this ID was removed.
Sourcepub fn all_nodes(&self) -> Vec<TreeRefId>
pub fn all_nodes(&self) -> Vec<TreeRefId>
Get the list of all the tree nodes.
Removed nodes won’t be in the list.
Sourcepub fn root_nodes(&self) -> Vec<TreeRefId>
pub fn root_nodes(&self) -> Vec<TreeRefId>
Get the list of the tree root nodes.
Sourcepub fn get(&self, id: TreeRefId) -> TreeRef<'a, '_>
pub fn get(&self, id: TreeRefId) -> TreeRef<'a, '_>
Get a reference to a tree node or panic if the ID does not exist.
For a non-panicking version, see Tree::try_get
.
§Panics
This function panics if the provided ID does not exist in the tree. It may happen if the node ID is hard-coded and is not yet present in the tree. Keep in mind that removing a node consumes the reference so this function is very unlikely to panic.
Sourcepub fn get_mut(&mut self, id: TreeRefId) -> TreeRefMut<'a, '_>
pub fn get_mut(&mut self, id: TreeRefId) -> TreeRefMut<'a, '_>
Get a mutable reference to a tree node or panic if the ID does not exist.
For a non-panicking version, see Tree::try_get_mut
.
§Panics
This function panics if the provided ID does not exist in the tree. It may happen if the node ID is hard-coded and is not yet present in the tree. Keep in mind that removing a node consumes the reference so this function is very unlikely to panic.
Sourcepub fn try_get(&self, id: TreeRefId) -> Option<TreeRef<'a, '_>>
pub fn try_get(&self, id: TreeRefId) -> Option<TreeRef<'a, '_>>
Try to get a tree reference from a node ID.
Returns None
if the ID is not present in tree.
Sourcepub fn try_get_mut(&mut self, id: TreeRefId) -> Option<TreeRefMut<'a, '_>>
pub fn try_get_mut(&mut self, id: TreeRefId) -> Option<TreeRefMut<'a, '_>>
Try to get a mutable tree reference from a node ID.
Returns None
if the ID is not present in tree.
pub fn traverse_breadth(&self) -> impl Iterator<Item = TreeRef<'a, '_>>
pub fn traverse_depth(&self) -> impl Iterator<Item = TreeRef<'a, '_>>
Sourcepub fn select<'b>(
&self,
selector: &'b str,
) -> Result<Option<TreeRefId>, SelectorParseError<'b>>
pub fn select<'b>( &self, selector: &'b str, ) -> Result<Option<TreeRefId>, SelectorParseError<'b>>
Search the first node matching the CSS selector in the tree, relatively to this node.
The traversal order used is the same as in the official DOM specification ie preorder, depth-first.
It is similar to the document.querySelector
function in JavaScript.
§Errors
Returns selectors::parser::SelectorParseError
if the CSS selector is not a valid CSS selector
or Ok(None)
if no node matching the CSS selector is found in the tree
Sourcepub fn select_all(&self, selector: &str) -> Vec<TreeRefId>
pub fn select_all(&self, selector: &str) -> Vec<TreeRefId>
Select several nodes in the tree using a CSS selector.
It is similar to the document.querySelectorAll
function in JavaScript.
Returns an empty Vec
if the selector is not a valid CSS selector.