[][src]Struct libwispha::core::Tree

pub struct Tree(_);

Wispha tree structure

Methods

impl Tree[src]

pub fn to_string(&self) -> Result<String, Error>[src]

Convert tree to JSON syntax

impl Tree[src]

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>
[src]

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

impl Tree[src]

pub fn new(config: &TreeConfig) -> Tree[src]

pub fn root(&self) -> Option<Rc<RefCell<Node>>>[src]

Get root. If the tree has no node, return None.

pub fn config(&self) -> TreeConfig[src]

pub fn get_node(&self, node_path: &NodePath) -> Option<Rc<RefCell<Node>>>[src]

Get node from the node_path

pub fn insert_node(
    &self,
    node_path: NodePath,
    node: Rc<RefCell<Node>>
) -> Option<Rc<RefCell<Node>>>
[src]

Insert node with node_path and node. If the node_path has already existed, the node is updated, and the old one is returned.

pub fn get_node_path(&self, node: Rc<RefCell<Node>>) -> NodePath[src]

Get the node path of node in tree

pub fn get_path_buf(&self, node_path: &NodePath) -> Result<PathBuf, Error>[src]

Get the os-related path of node in tree

pub fn clear(&self)[src]

Clear all the nodes in the tree

pub fn resolve_node<F>(
    &self,
    node_path: &NodePath,
    resolve_handler: &F,
    preserved_keys: &Vec<&'static str>
) -> Result<(), Error> where
    F: Fn(&LinkNode) -> Result<(PathBuf, String), Box<dyn Error>>, 
[src]

Resolve to make sure tree has a direct node value of key node_path.

resolve_handler does two things:

  • Convert link_node's target to a node_str contains the target's content
  • Check if a direct loop exists, i.e. the link_node's target is its record_file

pub fn resolve_in_depth<F>(
    &self,
    node_path: &NodePath,
    depth: usize,
    resolve_handler: &F,
    preserved_keys: &Vec<&'static str>
) -> Result<(), Error> where
    F: Fn(&LinkNode) -> Result<(PathBuf, String), Box<dyn Error>>, 
[src]

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 in depth (if exists) are of type DirectNode

The node_path itself's depth is 0

resolve_handler does two things:

  • Convert link_node's target to a node_str contains the target's content
  • Check if a direct loop exists, i.e. the link_node's target is its record_file

Trait Implementations

impl Debug for Tree[src]

Auto Trait Implementations

impl !RefUnwindSafe for Tree

impl !Send for Tree

impl !Sync for Tree

impl Unpin for Tree

impl !UnwindSafe for Tree

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.