pub struct Node {
pub field_string_data: String,
pub field_hash_map_children: HashMap<String, Node>,
}Fields§
§field_string_data: StringStores any within node
field_hash_map_children: HashMap<String, Node>Implementations§
source§impl Node
impl Node
sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
This removes all children without returning anything
sourcepub fn get_count_of_leaves(&self) -> usize
pub fn get_count_of_leaves(&self) -> usize
Returns usize count for leaves
sourcepub fn get_count_of_node_children(&self) -> usize
pub fn get_count_of_node_children(&self) -> usize
Returns a usize value representing the number of children this node possesses
sourcepub fn get_node_at_key(&self, arg_key: &str) -> Option<&Node>
pub fn get_node_at_key(&self, arg_key: &str) -> Option<&Node>
sourcepub fn get_node_at_path(&self, arg_path: &[&str]) -> Option<&Node>
pub fn get_node_at_path(&self, arg_path: &[&str]) -> Option<&Node>
sourcepub fn get_node_at_path_or_error(
&self,
arg_path: &[&str]
) -> Result<&Node, String>
pub fn get_node_at_path_or_error( &self, arg_path: &[&str] ) -> Result<&Node, String>
Returns the node referenced; or an error explaining where the path failed
Arguments
- arg_path: Path referring to node within sub-tree
sourcepub fn get_node_mut_at_key(&mut self, arg_key: &str) -> Option<&mut Node>
pub fn get_node_mut_at_key(&mut self, arg_key: &str) -> Option<&mut Node>
sourcepub fn get_node_mut_at_path(&mut self, arg_path: &[&str]) -> Option<&mut Node>
pub fn get_node_mut_at_path(&mut self, arg_path: &[&str]) -> Option<&mut Node>
Returns the node referenced as a mutable; or None
Arguments
- arg_path: Path referring to node within sub-tree
sourcepub fn get_node_mut_at_path_or_error(
&mut self,
arg_path: &[&str]
) -> Result<&mut Node, String>
pub fn get_node_mut_at_path_or_error( &mut self, arg_path: &[&str] ) -> Result<&mut Node, String>
Returns the node referenced as a mutable; or an error message explaining where the path failed
Arguments
- arg_path: Path referring to node within sub-tree
sourcepub fn get_node_parent(&self, arg_node: &Node) -> Option<&Node>
pub fn get_node_parent(&self, arg_node: &Node) -> Option<&Node>
sourcepub fn get_key_to_node(&self, arg_node: &Node) -> Option<String>
pub fn get_key_to_node(&self, arg_node: &Node) -> Option<String>
sourcepub fn get_path_to_node(&self, arg_node: &Node) -> Option<Vec<String>>
pub fn get_path_to_node(&self, arg_node: &Node) -> Option<Vec<String>>
Returns the path to the node, relative to the root node; or None
Arguments
- arg_node: This is the node searched for
sourcepub fn get_vec_of_keys(&self) -> Vec<String>
pub fn get_vec_of_keys(&self) -> Vec<String>
Returns a vec of keys for each immediate child of the root node
sourcepub fn get_vec_of_keys_sorted(&self) -> Vec<String>
pub fn get_vec_of_keys_sorted(&self) -> Vec<String>
Returns a vec of keys sorted
sourcepub fn get_vec_of_keys_all_ending_with_suffix(
&self,
arg_suffix: &str
) -> Vec<String>
pub fn get_vec_of_keys_all_ending_with_suffix( &self, arg_suffix: &str ) -> Vec<String>
Returns a vec of child keys, filtered by suffix Tip: Useful if running pop_node_and_promote_children_at_key()
Arguments
- arg_suffix: All keys possessing this suffix get returned
sourcepub fn get_vec_of_keys_all_ending_with_suffix_sorted(
&self,
arg_suffix: &str
) -> Vec<String>
pub fn get_vec_of_keys_all_ending_with_suffix_sorted( &self, arg_suffix: &str ) -> Vec<String>
Returns a vec of child keys, filtered by suffix and sorted Tip: Useful if running pop_node_and_promote_children_at_key()
Arguments
- arg_suffix: All keys possessing this suffix get returned
sourcepub fn get_vec_of_node_children(&self) -> Vec<&Node>
pub fn get_vec_of_node_children(&self) -> Vec<&Node>
Returns vec consisting of the root node’s immediate children
sourcepub fn get_vec_of_node_leaves(&self) -> Vec<&Node>
pub fn get_vec_of_node_leaves(&self) -> Vec<&Node>
Returns vec of nodes within subtree that have no children
sourcepub fn get_vec_of_nodes_along_path(
&self,
arg_path: &[&str]
) -> Option<Vec<&Node>>
pub fn get_vec_of_nodes_along_path( &self, arg_path: &[&str] ) -> Option<Vec<&Node>>
Returns vec of nodes along a given path; this does not include the root node
Arguments
- arg_path: This is the path along which the nodes will be collected
sourcepub fn get_vec_of_nodes_in_tree(&self) -> Vec<&Node>
pub fn get_vec_of_nodes_in_tree(&self) -> Vec<&Node>
Returns a vec of all nodes within the tree; this does not include the root node
sourcepub fn get_vec_of_nodes_satisfying_callback(
&self,
arg_callback: impl Fn(&Node) -> bool
) -> Vec<&Node>
pub fn get_vec_of_nodes_satisfying_callback( &self, arg_callback: impl Fn(&Node) -> bool ) -> Vec<&Node>
Returns a vec of all nodes that cause callback to return true
Arguments
- arg_callback: Receives a node and returns bool
sourcepub fn get_vec_of_pairs_keys_and_node_children(&self) -> Vec<(String, &Node)>
pub fn get_vec_of_pairs_keys_and_node_children(&self) -> Vec<(String, &Node)>
Returns a vec of tuple-pairs referring to the keys and node children
sourcepub fn get_vec_of_pairs_keys_and_node_mut_children(
&mut self
) -> Vec<(String, &mut Node)>
pub fn get_vec_of_pairs_keys_and_node_mut_children( &mut self ) -> Vec<(String, &mut Node)>
Returns a vec of tuple-pairs referring to the keys and node children
sourcepub fn get_vec_of_pairs_paths_and_nodes_with_data_satisfying_callback(
&self,
arg_callback: impl Fn(&Node) -> bool
) -> Vec<(Vec<String>, &Node)>
pub fn get_vec_of_pairs_paths_and_nodes_with_data_satisfying_callback( &self, arg_callback: impl Fn(&Node) -> bool ) -> Vec<(Vec<String>, &Node)>
Returns a vec of tuple-pairs consisting of paths and nodes; filtered by callback returning true Arguments
- arg_callback: Receives a node and returns bool
sourcepub fn get_vec_of_pairs_paths_and_nodes_with_data_satisfying_callback_sorted(
&self,
arg_callback: impl Fn(&Node) -> bool
) -> Vec<(Vec<String>, &Node)>
pub fn get_vec_of_pairs_paths_and_nodes_with_data_satisfying_callback_sorted( &self, arg_callback: impl Fn(&Node) -> bool ) -> Vec<(Vec<String>, &Node)>
Returns a sorted vec of tuple-pairs consisting of paths and nodes with data matching the argument; filtered by callback
Arguments
- arg_callback: Receives a node and returns bool
sourcepub fn get_vec_of_paths_in_tree(&self) -> Vec<Vec<String>>
pub fn get_vec_of_paths_in_tree(&self) -> Vec<Vec<String>>
Returns a vec of all paths within the tree
sourcepub fn get_vec_of_paths_in_tree_sorted(&self) -> Vec<Vec<String>>
pub fn get_vec_of_paths_in_tree_sorted(&self) -> Vec<Vec<String>>
Returns a vec of all paths within the tree, sorted
sourcepub fn get_vec_of_paths_to_node_leaves(&self) -> Vec<Vec<String>>
pub fn get_vec_of_paths_to_node_leaves(&self) -> Vec<Vec<String>>
Returns a vec of all paths pointing to nodes with no children
sourcepub fn get_vec_of_paths_to_nodes_satisfying_callback(
&self,
arg_callback: impl Fn(&Node) -> bool
) -> Vec<Vec<String>>
pub fn get_vec_of_paths_to_nodes_satisfying_callback( &self, arg_callback: impl Fn(&Node) -> bool ) -> Vec<Vec<String>>
Returns a vec of all paths pointing to nodes whose data satisfies the callback
Arguments
- arg_callback: Receives a node and returns bool.
sourcepub fn get_vec_of_paths_to_nodes_satisfying_callback_sorted(
&self,
arg_callback: impl Fn(&Node) -> bool
) -> Vec<Vec<String>>
pub fn get_vec_of_paths_to_nodes_satisfying_callback_sorted( &self, arg_callback: impl Fn(&Node) -> bool ) -> Vec<Vec<String>>
Returns a vec of paths to all nodes whose satisfies the callback
- arg_callback: Receives a node and returns bool
sourcepub fn insert_node_at_key(
&mut self,
arg_key: &str,
arg_node: Node
) -> Result<(), String>
pub fn insert_node_at_key( &mut self, arg_key: &str, arg_node: Node ) -> Result<(), String>
Adds node at the designated key. WARNING: The tree needs to take ownership of this node upon passing
Arguments
- arg_key: A key of type &str used to identify a child node
- arg_node: This is node to add at the end of the path
sourcepub fn insert_node_at_path(
&mut self,
arg_path: &[&str],
arg_node: Node
) -> Result<(), String>
pub fn insert_node_at_path( &mut self, arg_path: &[&str], arg_node: Node ) -> Result<(), String>
Adds node at path. Returns the parent of the new node. Despite the return value being ‘optional’ this will always return a Node. WARNING: The tree needs to take ownership of this node upon passing The function will create any necessary intermediate nodes along its approach
Arguments
- arg_path: Slice of &str keys which is use to navigate from the node of origin to the descendant node
- arg_node: This is node to add at the end of the path
sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if the root node has children
sourcepub fn has_key(&self, arg_key: &str) -> bool
pub fn has_key(&self, arg_key: &str) -> bool
Returns true if the key exists for an immediate child
Arguments
- arg_key: A key of type &str used to identify a child node
sourcepub fn has_path(&self, arg_path: &[&str]) -> bool
pub fn has_path(&self, arg_path: &[&str]) -> bool
Returns true if function can travers entire path without encountering a missing node
Arguments
- arg_path: Slice of &str keys which is use to navigate from the node of origin to the descendant node
sourcepub fn is_path_valid(&self, arg_path: &[&str]) -> bool
pub fn is_path_valid(&self, arg_path: &[&str]) -> bool
Returns true if all path elements are valid (is not empty, and has no empty components)
sourcepub fn pop_all_children_and_return_vec_of_pairs_keys_and_child_nodes(
&mut self
) -> Option<Vec<(String, Node)>>
pub fn pop_all_children_and_return_vec_of_pairs_keys_and_child_nodes( &mut self ) -> Option<Vec<(String, Node)>>
Returns a vec of tuple pairs: key and node, and removes them all from this node
sourcepub fn pop_node_at_key_and_promote_its_children(
&mut self,
arg_key: &str,
arg_collision_suffix: &str
) -> Result<Node, String>
pub fn pop_node_at_key_and_promote_its_children( &mut self, arg_key: &str, arg_collision_suffix: &str ) -> Result<Node, String>
Pops a child, and promotes all of its children to become parents of this node
Arguments
- arg_key: The str key to pop
- arg_collision_suffix: Custom suffix to append to all promoted nodes
sourcepub fn pop_node_at_path_and_promote_its_children(
&mut self,
arg_path: &[&str],
arg_collision_suffix: &str
) -> Result<Node, String>
pub fn pop_node_at_path_and_promote_its_children( &mut self, arg_path: &[&str], arg_collision_suffix: &str ) -> Result<Node, String>
Pops a child, and promotes all of its children to become parents of this node
sourcepub fn pop_node_at_key(&mut self, arg_key: &str) -> Option<Node>
pub fn pop_node_at_key(&mut self, arg_key: &str) -> Option<Node>
Returns the node stored at the key; the tree will relinquish ownership of this node
Arguments
- arg_key: A key of type &str used to identify a child node
sourcepub fn pop_node_at_path(&mut self, arg_path: &[&str]) -> Option<Node>
pub fn pop_node_at_path(&mut self, arg_path: &[&str]) -> Option<Node>
Returns the node stored at the path; the tree will relinquish ownership of this node
Arguments
- arg_path: Slice of &str keys which is use to navigate from the node of origin to the descendant node
sourcepub fn pop_node_at_path_or_error(
&mut self,
arg_path: &[&str]
) -> Result<Node, String>
pub fn pop_node_at_path_or_error( &mut self, arg_path: &[&str] ) -> Result<Node, String>
Returns the node stored at the path; the tree will relinquish ownership of this node If the path fails, then the function will return an error message explaining where the path failed
Arguments
- arg_path: Slice of &str keys which is use to navigate from the node of origin to the descendant node
sourcepub fn raise_error_if_key_is_invalid(arg_key: &str) -> Result<(), String>
pub fn raise_error_if_key_is_invalid(arg_key: &str) -> Result<(), String>
Returns an error if string is invalid