1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::collections::HashMap;
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::path::PathBuf;
use serde::Serialize;
type NodePathComponents = Vec<String>;
#[derive(Clone, Debug, Default)]
pub struct NodePath {
pub(crate) components: NodePathComponents,
pub(crate) tree: Weak<RefCell<InnerTree>>
}
#[derive(Clone, Serialize, Debug)]
pub struct NodeProperties {
pub name: String,
#[serde(skip)]
pub parent: Option<NodePath>,
#[serde(skip)]
pub record_file: PathBuf,
}
#[derive(Debug)]
pub struct DirectNode {
pub children: Vec<NodePath>,
pub node_properties: NodeProperties,
pub properties: HashMap<String, String>,
}
#[derive(Serialize, Debug)]
pub struct LinkNode {
pub target: PathBuf,
#[serde(flatten)]
pub node_properties: NodeProperties,
}
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
pub enum Node {
Direct(DirectNode),
Link(LinkNode),
}
#[derive(Debug, Clone)]
pub struct TreeConfig {
pub project_name: String,
}
#[derive(Debug)]
pub(crate) struct InnerTree {
pub nodes: HashMap<NodePathComponents, Rc<RefCell<Node>>>,
pub config: TreeConfig
}
#[derive(Debug)]
pub struct Tree(pub(crate) Rc<RefCell<InnerTree>>);