Struct Tree

Source
pub struct Tree(/* private fields */);
Expand description

Wispha tree structure

Implementations§

Source§

impl Tree

Source

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

Convert tree to JSON syntax

Source§

impl Tree

Source

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

Source

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

Source

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

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

Source

pub fn config(&self) -> TreeConfig

Source

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

Get node from the node_path

Source

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.

Source

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

Get the node path of node in tree

Source

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

Get the os-related path of node in tree

Source

pub fn clear(&self)

Clear all the nodes in the tree

Source

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>>,

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
Source

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>>,

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§

Source§

impl Debug for Tree

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl !RefUnwindSafe for Tree

§

impl !Send for Tree

§

impl !Sync for Tree

§

impl Unpin for Tree

§

impl !UnwindSafe for Tree

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.