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 = [0]
   1 = [0,0]
   2 = [0,0,0]
   3 = [0,0,1]
   4 = [0,1]
   5 = [0,1,0]
   6 = [0,1,1]
   7 = [0,1,2]

Fields

path: Vec<usize>

an alternative path vector, where it specifies the first element is the index of the root node which is always 0 the second element is the index of the child to traverse to and so on. Given a DOM tree where node_idx and path was derived from, we can verify that node_idx and path point to the same node. The advantage of using this is that this doesn’t need to traverse nodes that are not relevant. Traversal operation complexity is O(log n)

Implementations

create a TreePath with node index node_idx and traversal path path

add a path node idx

find the node using the path of this tree path

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.