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
impl TreePath
sourcepub fn new(path: impl IntoIterator<Item = usize>) -> TreePath
pub fn new(path: impl IntoIterator<Item = usize>) -> TreePath
create a TreePath with node index node_idx
and traversal path path
sourcepub fn root() -> TreePath
pub fn root() -> TreePath
create a TreePath which starts at empty vec which is the root node of a DOM tree
sourcepub fn traverse(&self, node_idx: usize) -> TreePath
pub fn traverse(&self, node_idx: usize) -> TreePath
create a new TreePath with an added node_index This is used for traversing into child elements
sourcepub fn remove_first(&mut self) -> usize
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
sourcepub fn next_sibling(&self) -> TreePath
pub fn next_sibling(&self) -> TreePath
go to the next sibling
sourcepub fn jump_to_sibling(&self, n: usize) -> TreePath
pub fn jump_to_sibling(&self, n: usize) -> TreePath
jump to the sibling n
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
returns tree if the path is empty This is used for checking if the path has been traversed
sourcepub fn find_node_by_path<'a, MSG>(
&self,
node: &'a Node<MSG>
) -> Option<&'a Node<MSG>>
pub fn find_node_by_path<'a, MSG>( &self, node: &'a Node<MSG> ) -> Option<&'a Node<MSG>>
find the node using the path of this tree path
Trait Implementations§
source§impl Ord for TreePath
impl Ord for TreePath
source§impl PartialEq for TreePath
impl PartialEq for TreePath
source§impl PartialOrd for TreePath
impl PartialOrd for TreePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for TreePath
impl StructuralPartialEq for TreePath
Auto Trait Implementations§
impl Freeze for TreePath
impl RefUnwindSafe for TreePath
impl Send for TreePath
impl Sync for TreePath
impl Unpin for TreePath
impl UnwindSafe for TreePath
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.