1use crate::{make_unmergeable_dir_content_mergeable, FileSystemTree, MergeableFileSystemTree};
2use pipe_trait::Pipe;
3use std::collections::BTreeMap;
4
5pub trait Node {
7 type FileContent;
9 type DirectoryContent;
11 fn read(self) -> NodeContent<Self::FileContent, Self::DirectoryContent>;
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum NodeContent<FileContent, DirectoryContent> {
22 File(FileContent),
24 Directory(DirectoryContent),
26}
27
28impl<Path, FileContent> Node for FileSystemTree<Path, FileContent>
29where
30 Path: Ord,
31{
32 type FileContent = FileContent;
33 type DirectoryContent = BTreeMap<Path, Self>;
34
35 fn read(self) -> NodeContent<FileContent, Self::DirectoryContent> {
36 match self {
37 FileSystemTree::File(content) => NodeContent::File(content),
38 FileSystemTree::Directory(content) => NodeContent::Directory(content),
39 }
40 }
41}
42
43impl<Path, FileContent> Node for MergeableFileSystemTree<Path, FileContent>
44where
45 Path: Ord,
46{
47 type FileContent = FileContent;
48 type DirectoryContent = BTreeMap<Path, Self>;
49
50 fn read(self) -> NodeContent<FileContent, Self::DirectoryContent> {
51 match self.into() {
52 FileSystemTree::File(content) => NodeContent::File(content),
53 FileSystemTree::Directory(content) => content
54 .pipe(make_unmergeable_dir_content_mergeable)
55 .pipe(NodeContent::Directory),
56 }
57 }
58}