pub struct Tree(/* private fields */);
Expand description
Wispha tree structure
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn insert_nodes_from_str(
&self,
node_str: &str,
recorded_file: PathBuf,
parent_and_given_name: Option<(NodePath, String)>,
preserved_keys: &Vec<&'static str>,
) -> Result<Rc<RefCell<Node>>, Error>
pub fn insert_nodes_from_str( &self, node_str: &str, recorded_file: PathBuf, parent_and_given_name: Option<(NodePath, String)>, preserved_keys: &Vec<&'static str>, ) -> Result<Rc<RefCell<Node>>, Error>
Insert nodes from JSON string node_str
in recorded_file
to tree
.
If node_str
is the root of Wispha tree, parent_and_given_name
should be None
;
else parent
should be the node_str
’s parent, given_name
should be the link node’s name
Source§impl Tree
impl Tree
pub fn new(config: &TreeConfig) -> Tree
Sourcepub fn root(&self) -> Option<Rc<RefCell<Node>>>
pub fn root(&self) -> Option<Rc<RefCell<Node>>>
Get root. If the tree has no node, return None
.
pub fn config(&self) -> TreeConfig
Sourcepub fn get_node(&self, node_path: &NodePath) -> Option<Rc<RefCell<Node>>>
pub fn get_node(&self, node_path: &NodePath) -> Option<Rc<RefCell<Node>>>
Get node from the node_path
Sourcepub fn insert_node(
&self,
node_path: NodePath,
node: Rc<RefCell<Node>>,
) -> Option<Rc<RefCell<Node>>>
pub fn insert_node( &self, node_path: NodePath, node: Rc<RefCell<Node>>, ) -> Option<Rc<RefCell<Node>>>
Insert node with node_path
and node
.
If the node_path
has already existed, the node is updated, and the old one is returned.
Sourcepub fn get_node_path(&self, node: Rc<RefCell<Node>>) -> NodePath
pub fn get_node_path(&self, node: Rc<RefCell<Node>>) -> NodePath
Get the node path of node
in tree
Sourcepub fn get_path_buf(&self, node_path: &NodePath) -> Result<PathBuf, Error>
pub fn get_path_buf(&self, node_path: &NodePath) -> Result<PathBuf, Error>
Get the os-related path of node
in tree
Sourcepub fn resolve_node<F>(
&self,
node_path: &NodePath,
resolve_handler: &F,
preserved_keys: &Vec<&'static str>,
) -> Result<(), Error>
pub fn resolve_node<F>( &self, node_path: &NodePath, resolve_handler: &F, preserved_keys: &Vec<&'static str>, ) -> Result<(), Error>
Resolve to make sure tree has a direct node value of key node_path
.
resolve_handler
does two things:
- Convert
link_node
’starget
to a node_str contains thetarget
’s content - Check if a direct loop exists, i.e. the
link_node
’starget
is itsrecord_file
Sourcepub fn resolve_in_depth<F>(
&self,
node_path: &NodePath,
depth: usize,
resolve_handler: &F,
preserved_keys: &Vec<&'static str>,
) -> Result<(), Error>
pub fn resolve_in_depth<F>( &self, node_path: &NodePath, depth: usize, resolve_handler: &F, preserved_keys: &Vec<&'static str>, ) -> Result<(), Error>
Update the tree
’s nodes
, starting from node_path
, with depth depth
, to direct node,
using resolve_handler
to convert from PathBuf
to Node
.
If this function returns Ok
, it means two things:
- The
node_path
does exist in the tree - The children of
node_path
indepth
(if exists) are of typeDirectNode
The node_path
itself’s depth
is 0
resolve_handler
does two things:
- Convert
link_node
’starget
to a node_str contains thetarget
’s content - Check if a direct loop exists, i.e. the
link_node
’starget
is itsrecord_file