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
use crate::node::Tree;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
#[derive(Debug, Serialize, Deserialize)]
pub struct Forest {
tree: Tree,
projects: HashMap<PathBuf, Tree>,
}
impl Forest {
pub fn new(tree: Tree) -> Self {
Self {
tree,
projects: HashMap::new(),
}
}
pub fn main_tree(&self) -> &Tree {
&self.tree
}
pub fn cwd_tree(&self, cwd: impl AsRef<Path>) -> Option<&Tree> {
self.projects.get(cwd.as_ref())
}
pub fn add_cwd_tree(&mut self, cwd: impl Into<PathBuf>, tree: Tree) {
let _ = self.projects.insert(cwd.into(), tree);
}
}