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
use crate::{Build, FileSystemTree, MergeableFileSystemTree, Node};
use pipe_trait::Pipe;
use serde::de::DeserializeOwned;
use serde_yaml::from_reader;
use std::{fmt::Debug, io, path::PathBuf};
pub fn run<Tree, Path>(target: &Path) -> Result<(), String>
where
Tree: Build<Path, io::Error, Path = Path> + Node + DeserializeOwned,
Tree::DirectoryContent: IntoIterator<Item = (Path, Tree)>,
Path: Debug + Ord,
{
io::stdin()
.pipe(from_reader::<_, Tree>)
.map_err(|error| format!("error: Read from stdin: {:?}", error))?
.build(target)
.map_err(|error| error.to_string())
}
pub type Run = fn(&PathBuf) -> Result<(), String>;
pub const CREATE: Run = run::<FileSystemTree<PathBuf, String>, PathBuf>;
pub const POPULATE: Run = run::<MergeableFileSystemTree<PathBuf, String>, PathBuf>;