Struct Tree

Source
pub struct Tree<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Tree<'a>

Source

pub fn new<P: AsRef<Path>>(file_path: P) -> Self

Create an empty Tree.

Source

pub fn file_path(&self) -> &Path

Source

pub fn next_id(&self) -> TreeRefId

Source

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.

Source

pub fn all_nodes(&self) -> Vec<TreeRefId>

Get the list of all the tree nodes.

Removed nodes won’t be in the list.

Source

pub fn root_nodes(&self) -> Vec<TreeRefId>

Get the list of the tree root nodes.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn traverse_breadth(&self) -> impl Iterator<Item = TreeRef<'a, '_>>

Source

pub fn traverse_depth(&self) -> impl Iterator<Item = TreeRef<'a, '_>>

Source

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

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for Tree<'a>

Source§

fn clone(&self) -> Tree<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Tree<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Tree<'a>

§

impl<'a> RefUnwindSafe for Tree<'a>

§

impl<'a> Send for Tree<'a>

§

impl<'a> Sync for Tree<'a>

§

impl<'a> Unpin for Tree<'a>

§

impl<'a> UnwindSafe for Tree<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.