Skip to main content

ProjectTree

Struct ProjectTree 

Source
pub struct ProjectTree {
    pub id: String,
    pub name: String,
    pub path: String,
    pub root: Option<TreeNode>,
    pub config: Option<ProjectConfig>,
}
Expand description

项目目录树根节点 用于初始化操作和启动目录树分析

Fields§

§id: String

项目 ID,自动生成

§name: String

项目别名,自定义

§path: String

项目根路径,自定义

§root: Option<TreeNode>

根节点,在 build 方法中生成,作为整个项目树迭代入口

§config: Option<ProjectConfig>

项目树迭代配置,用于过滤、仅包含等等

Implementations§

Source§

impl ProjectTree

初始化项目及构建属性

Source

pub fn new<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
where S: Into<String>, I: Into<String>,

通过一系列参数初始化项目树

  • name:项目别名
  • path:根路径
  • config:配置

但是需要注意,该操作仅初始化一个基础的项目树对象,可以通过该对象启动项目树的构建和分析:

  • build: 构建项目树,生成各个节点,但不包含总结信息
  • summarize: 遍历已有项目树,获取各个节点的总结信息
§Example
use arui_core::tree::root::ProjectTree;
const NAME: &str = "test";
const PATH: &str = ".";
// 需要使用可变类型来初始化
let mut project = ProjectTree::new(NAME, PATH, None);
// 需要通过 build 和 summary 方法来启动项目树的构建和分析
project.build().unwrap();
project.summarize().unwrap();
Source

pub fn is_valid(&self) -> bool

动态检查节点路径是否合法

§Example
use arui_core::tree::root::ProjectTree;
// 只有在路径合法的情况下,才能进行项目树构建,但可正常初始化项目
let can_build = ProjectTree::new("test", "/@not_exist", None).is_valid();
println!("{}", can_build); // should be false
Source

pub fn plant<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
where S: Into<String>, I: Into<String>,

“种植“一棵项目树

  • name:项目别名
  • path:根路径
  • config:配置

该操作和 new 的不同的地方在于,new 方法仅初始化项目树入口,并不完成后续操作:

  • build: 从 path 启动,遍历并生成项目树
  • summary: 从 root 启动,遍历并生成项目树各节点的总结信息
§Example
use arui_core::tree::root::ProjectTree;
const NAME: &str = "test";
const PATH: &str = ".";
// 如果只用 `plant`,后续也不需要更新项目树,则可不使用 `mut`
let project = ProjectTree::plant(NAME, PATH, None);
Source

pub fn build(&mut self) -> Result<()>

构建项目文件树(不包含summary信息) 通过 path 启动,遍历并生成项目树,但仅初始化各级树结构:

  • path:节点对应文件/目录的路径
  • is_dir:是否是文件夹
  • children:子节点(is_dir为true时有值) 其中并不包含 summary 字段的获取,需要单独调用 summarize 方法来获取
§Example
use arui_core::tree::root::ProjectTree;
let mut project = ProjectTree::new("test", "./src", None);
project.build().unwrap();
Source

pub fn summarize(&mut self) -> Result<()>

生成项目树的总结信息 从 root 启动,遍历并生成项目树各节点的总结信息

§Example
use arui_core::tree::root::ProjectTree;
let mut project = ProjectTree::new("test", "./src", None);
project.build().unwrap();
project.summarize().unwrap();
println!("{}", project.root.as_ref().unwrap());

Trait Implementations§

Source§

impl Display for ProjectTree

Source§

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

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

impl ProjectTreeVisible for ProjectTree

Source§

fn show(&self)

列出项目根节点信息:

  • ID: 项目根节点的唯一标识
  • Valid:是否为有效树,即树结构存在于目标路径下
  • Name: 项目名
  • Path: 项目根路径
§Examples
use arui_core::tree::root::ProjectTree;
use arui_core::tree::visible::ProjectTreeVisible;
let tree = ProjectTree::new("test", ".", None);
tree.show();
Source§

fn print_tree(&self)

打印整个树结构

Source§

fn print_node(node: &TreeNode, depth: usize)

递归打印节点

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