Struct mt_dom::patch::TreePath

source ·
pub struct TreePath {
    pub path: Vec<usize>,
}
Expand description

Describe the path traversal of a Node starting from the root node

The figure below shows node_idx in a depth first traversal.

           .─.
          ( 0 )
           `-'
          /   \
         /     \
        /       \
       ▼         ▼
      .─.         .─.
     ( 1 )       ( 4 )
      `-'         `-'
     /  \          | \ '.
    /    \         |  \  '.
   ▼      ▼        |   \   '.
 .─.      .─.      ▼    ▼     ▼
( 2 )    ( 3 )    .─.   .─.   .─.
 `─'      `─'    ( 5 ) ( 6 ) ( 7 )
                  `─'   `─'   `─'

The figure below shows the index of each child node relative to their parent node

            .─.
           ( 0 )
            `-'
           /   \
          /     \
         /       \
        ▼         ▼
       .─.         .─.
      ( 0 )       ( 1 )
       `-'         `-'
      /  \          | \ '.
     /    \         |  \  '.
    ▼      ▼        |   \   '.
  .─.      .─.      ▼    ▼     ▼
 ( 0 )    ( 1 )    .─.   .─.   .─.
  `─'      `─'    ( 0 ) ( 1 ) ( 2 )
                   `─'   `─'   `─'

The equivalent idx and path are as follows:

   0 = []
   1 = [0]
   2 = [0,0]
   3 = [0,1]
   4 = [1]
   5 = [1,0]
   6 = [1,1]
   7 = [1,2]

Fields§

§path: Vec<usize>

An array of child index at each level of the dom tree. The children of the nodes at each child index is traverse at each traversal the first element of path is removed until the path becomes empty. If the path has become empty the node is said to be found.

Empty path means root node

Implementations§

source§

impl TreePath

source

pub fn new(path: impl IntoIterator<Item = usize>) -> Self

create a TreePath with node index node_idx and traversal path path

source

pub fn root() -> Self

create a TreePath which starts at empty vec which is the root node of a DOM tree

source

pub fn push(&mut self, node_idx: usize)

add a path node idx

source

pub fn traverse(&self, node_idx: usize) -> Self

create a new TreePath with an added node_index This is used for traversing into child elements

source

pub fn backtrack(&self) -> Self

backtrack to the parent node path

source

pub fn remove_first(&mut self) -> usize

remove first node index of this treepath Everytime a node is traversed, the first element should be removed until no more index is in this path

source

pub fn pluck(&mut self) -> usize

pluck the next in line node index in this treepath

source

pub fn is_empty(&self) -> bool

returns tree if the path is empty This is used for checking if the path has been traversed

source

pub fn find_node_by_path<'a, Ns, Tag, Leaf, Att, Val>( &self, node: &'a Node<Ns, Tag, Leaf, Att, Val> ) -> Option<&'a Node<Ns, Tag, Leaf, Att, Val>>
where Ns: PartialEq + Clone + Debug, Tag: PartialEq + Clone + Debug, Leaf: PartialEq + Clone + Debug, Att: PartialEq + Clone + Debug, Val: PartialEq + Clone + Debug,

find the node using the path of this tree path

Trait Implementations§

source§

impl Clone for TreePath

source§

fn clone(&self) -> TreePath

Returns a copy 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 Debug for TreePath

source§

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

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

impl<const N: usize> From<[usize; N]> for TreePath

source§

fn from(array: [usize; N]) -> Self

Converts to this type from the input type.
source§

impl From<Vec<usize>> for TreePath

source§

fn from(vec: Vec<usize>) -> Self

Converts to this type from the input type.
source§

impl Ord for TreePath

source§

fn cmp(&self, other: &TreePath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for TreePath

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for TreePath

source§

fn partial_cmp(&self, other: &TreePath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for TreePath

source§

impl StructuralPartialEq for TreePath

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

§

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

§

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

§

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.