Skip to main content

TreeNode

Struct TreeNode 

Source
pub struct TreeNode {
    pub path: String,
    pub is_dir: bool,
    pub children: Option<Vec<TreeNode>>,
    pub summary: NodeSummary,
}
Expand description

目录树节点

  • 节点为文件时,无子树
  • 节点为目录时,有子树

Fields§

§path: String

当前节点所处路径

§is_dir: bool

是否是目录 TODO:后续应该改为自动检测

§children: Option<Vec<TreeNode>>

如果是目录,那么遍历他的子节点;如果为文件,则为空

§summary: NodeSummary

节点总结信息

  • 文件:当前文件的总结信息
  • 目录:当前目录下所有文件的总结信息的加合

Implementations§

Source§

impl TreeNode

节点配置相关

Source

pub fn new<P>(path: P, is_dir: bool) -> Self
where P: Into<String>,

创建一个项目树节点

§Examples
use arui_core::tree::node::TreeNode;
let node = TreeNode::new("./src", true);
Source

pub fn is_valid(&self) -> bool

检测节点路径是否合法

§Examples
use arui_core::tree::node::TreeNode;

let valid = TreeNode::new("./src", true).is_valid();
assert_eq!(valid, true);

let in_valid = TreeNode::new("/not_exist", true).is_valid();
assert_eq!(in_valid, false);
Source§

impl TreeNode

为节点实现总结信息相关操作

Source

pub fn upsert_summary(&mut self)

初次调用为获取节点总结信息 重复调用为更新节点总结信息,覆盖式更新当前节点的总结信息

§Examples
use arui_core::tree::node::TreeNode;

// 初始化目录节点,无子节点
let mut folder_node = TreeNode::new("./src", true);
// 初始获取总结信息
folder_node.upsert_summary();
assert_eq!(folder_node.summary.size, 0);
assert_eq!(folder_node.summary.count, 0);

// 加入子节点
let sub_node = TreeNode::new("./src/lib.rs", false);
folder_node.children = Some(vec![sub_node]);
// 重复调用,覆盖式更新节点总结信息
folder_node.upsert_summary();
assert_eq!(folder_node.summary.size > 0, true);
assert_eq!(folder_node.summary.count > 0, true);

// 初始化文件节点
let mut file_node = TreeNode::new("./src/lib.rs", false);
file_node.upsert_summary();
assert_eq!(file_node.summary.size > 0, true);
assert_eq!(file_node.summary.count > 0, true);

Trait Implementations§

Source§

impl Clone for TreeNode

Source§

fn clone(&self) -> TreeNode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TreeNode

Source§

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

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

impl Display for TreeNode

为节点实现 Display

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.