Struct data_tree::Node

source ·
pub struct Node {
    pub field_string_data: String,
    pub field_hash_map_children: HashMap<String, Node>,
}

Fields§

§field_string_data: String

Stores any within node

§field_hash_map_children: HashMap<String, Node>

Implementations§

source§

impl Node

source

pub fn clear_children(&mut self)

This removes all children without returning anything

source

pub fn get_count_of_leaves(&self) -> usize

Returns usize count for leaves

source

pub fn get_count_of_node_children(&self) -> usize

Returns a usize value representing the number of children this node possesses

source

pub fn get_node_at_key(&self, arg_key: &str) -> Option<&Node>

Returns the node reference; or None

Arguments
  • arg_key: Key referring to the child node
source

pub fn get_node_at_path(&self, arg_path: &[&str]) -> Option<&Node>

Returns the node referenced; or None

Arguments
  • arg_path: Path referring to node within sub-tree
source

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
source

pub fn get_node_mut_at_key(&mut self, arg_key: &str) -> Option<&mut Node>

Returns the node referenced as a mutable; or None

Arguments
  • arg_key: Key referring to child node
source

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
source

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
source

pub fn get_node_parent(&self, arg_node: &Node) -> Option<&Node>

Returns the parent of a given node; or None

Arguments
  • arg_node: The node with the parent
source

pub fn get_key_to_node(&self, arg_node: &Node) -> Option<String>

Returns the key pointing to arg_node

Arguments
  • arg_node: This is the node searched for
source

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
source

pub fn get_vec_of_keys(&self) -> Vec<String>

Returns a vec of keys for each immediate child of the root node

source

pub fn get_vec_of_keys_sorted(&self) -> Vec<String>

Returns a vec of keys sorted

source

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
source

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
source

pub fn get_vec_of_node_children(&self) -> Vec<&Node>

Returns vec consisting of the root node’s immediate children

source

pub fn get_vec_of_node_leaves(&self) -> Vec<&Node>

Returns vec of nodes within subtree that have no children

source

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
source

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

source

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
source

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

source

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

source

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
source

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
source

pub fn get_vec_of_paths_in_tree(&self) -> Vec<Vec<String>>

Returns a vec of all paths within the tree

source

pub fn get_vec_of_paths_in_tree_sorted(&self) -> Vec<Vec<String>>

Returns a vec of all paths within the tree, sorted

source

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

source

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.
source

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
source

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
source

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
source

pub fn has_children(&self) -> bool

Returns true if the root node has children

source

pub fn has_data(&self) -> bool

Returns true if the string within the node contains any data

source

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
source

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
source

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)

source

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

source

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
source

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

source

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
source

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
source

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
source

pub fn raise_error_if_key_is_invalid(arg_key: &str) -> Result<(), String>

Returns an error if string is invalid

source

pub fn raise_error_if_path_is_invalid( &self, arg_path: &[&str] ) -> Result<(), String>

Returns an error if the path is invalid; otherwise it returns () See is_path_valid() for criteria

source

pub fn new() -> Self

Get new node instance

Trait Implementations§

source§

impl Debug for Node

source§

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

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

impl<'de> Deserialize<'de> for Node

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Node

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,