build_fs_tree/build/
impl_mergeable_tree.rs1use crate::{Build, MergeableFileSystemTree};
2use std::{
3 fs::{create_dir_all, write},
4 io::Error,
5 path::{Path, PathBuf},
6};
7
8impl<Name, FileContent> Build<Name, Error> for MergeableFileSystemTree<Name, FileContent>
9where
10 Name: AsRef<Path> + Ord,
11 FileContent: AsRef<[u8]>,
12{
13 type BorrowedPath = Path;
14 type OwnedPath = PathBuf;
15
16 fn join(prefix: &Self::BorrowedPath, name: &Name) -> Self::OwnedPath {
17 prefix.join(name)
18 }
19
20 fn write_file(path: &Self::BorrowedPath, content: &Self::FileContent) -> Result<(), Error> {
21 if let Some(dir) = path.parent() {
22 create_dir_all(dir)?;
23 }
24 write(path, content)
25 }
26
27 fn create_dir(path: &Self::BorrowedPath) -> Result<(), Error> {
28 create_dir_all(path)
29 }
30}