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
初始化项目及构建属性
impl ProjectTree
初始化项目及构建属性
Sourcepub fn new<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
pub fn new<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
通过一系列参数初始化项目树
- 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();Sourcepub fn is_valid(&self) -> bool
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 falseSourcepub fn plant<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
pub fn plant<S, I>(name: S, path: I, config: Option<ProjectConfig>) -> Self
“种植“一棵项目树
- 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);Sourcepub fn build(&mut self) -> Result<()>
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();Trait Implementations§
Source§impl Display for ProjectTree
impl Display for ProjectTree
Source§impl ProjectTreeVisible for ProjectTree
impl ProjectTreeVisible for ProjectTree
Source§fn show(&self)
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)
fn print_tree(&self)
打印整个树结构
Source§fn print_node(node: &TreeNode, depth: usize)
fn print_node(node: &TreeNode, depth: usize)
递归打印节点
Auto Trait Implementations§
impl Freeze for ProjectTree
impl RefUnwindSafe for ProjectTree
impl Send for ProjectTree
impl Sync for ProjectTree
impl Unpin for ProjectTree
impl UnsafeUnpin for ProjectTree
impl UnwindSafe for ProjectTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more