build_fs_tree/
tree.rs

1mod dir_content;
2
3pub use dir_content::*;
4
5use derive_more::{AsMut, AsRef, Deref, DerefMut, From, Into};
6use serde::{Deserialize, Serialize};
7use std::collections::BTreeMap;
8
9/// Representation of a filesystem which contains only [files](FileSystemTree::File)
10/// and [directories](FileSystemTree::Directory).
11///
12/// The serialization of `FileContent` (content of file) and `BTreeMap<Path, Self>`
13/// (children of directory) must not share the same type. That is, `FileContent` must
14/// be serialized to things other than a dictionary.
15///
16/// **Note:** [`FileSystemTree::build`](crate::Build::build) cannot write over an existing
17/// directory. Use [`MergeableFileSystemTree`] instead if you desire such behavior.
18///
19/// **Generic parameters:**
20/// * `Path`: Reference to a file in the filesystem.
21/// * `FileContent`: Content of a file.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum FileSystemTree<Path, FileContent>
25where
26    Path: Ord,
27{
28    /// Represents a file with its content.
29    /// Its YAML representation must not have the same type as [`FileSystemTree::Directory`]'s.
30    File(FileContent),
31    /// Represents a directory with its children.
32    /// It is a set of name-to-subtree mappings.
33    /// Its YAML representation must not have the same type as [`FileSystemTree::File`]'s.
34    Directory(BTreeMap<Path, Self>),
35}
36
37/// Representation of a filesystem which contains only [files](FileSystemTree::File)
38/// and [directories](FileSystemTree::Directory).
39///
40/// The serialization of `FileContent` (content of file) and `BTreeMap<Path, Self>`
41/// (children of directory) must not share the same type. That is, `FileContent` must
42/// be serialized to things other than a dictionary.
43///
44/// **Generic parameters:**
45/// * `Path`: Reference to a file in the filesystem.
46/// * `FileContent`: Content of a file.
47///
48/// **Difference from [`FileSystemTree`]:**
49/// [`FileSystemTree::build`](crate::Build::build) cannot write over an existing directory.
50/// On the other hand, [`MergeableFileSystemTree::build`](crate::Build::build) either merges
51/// the two directories if there's no conflict.
52#[derive(
53    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, AsMut, AsRef, Deref, DerefMut, From, Into,
54)]
55pub struct MergeableFileSystemTree<Path, FileContent>(FileSystemTree<Path, FileContent>)
56where
57    Path: Ord;
58
59mod methods;