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
use crate::{make_unmergeable_dir_content_mergeable, FileSystemTree, MergeableFileSystemTree};
use pipe_trait::Pipe;
use std::collections::BTreeMap;
pub trait Node {
type FileContent;
type DirectoryContent;
fn read(self) -> NodeContent<Self::FileContent, Self::DirectoryContent>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeContent<FileContent, DirectoryContent> {
File(FileContent),
Directory(DirectoryContent),
}
impl<Path, FileContent> Node for FileSystemTree<Path, FileContent>
where
Path: Ord,
{
type FileContent = FileContent;
type DirectoryContent = BTreeMap<Path, Self>;
fn read(self) -> NodeContent<FileContent, Self::DirectoryContent> {
match self {
FileSystemTree::File(content) => NodeContent::File(content),
FileSystemTree::Directory(content) => NodeContent::Directory(content),
}
}
}
impl<Path, FileContent> Node for MergeableFileSystemTree<Path, FileContent>
where
Path: Ord,
{
type FileContent = FileContent;
type DirectoryContent = BTreeMap<Path, Self>;
fn read(self) -> NodeContent<FileContent, Self::DirectoryContent> {
match self.into() {
FileSystemTree::File(content) => NodeContent::File(content),
FileSystemTree::Directory(content) => content
.pipe(make_unmergeable_dir_content_mergeable)
.pipe(NodeContent::Directory),
}
}
}