macro_rules! tree { ($($all:tt)+) => { ... }; }
Expand description
Macro for declaring a FsTree
literal.
Syntax:
name
is a regular file.name: { ... }
is a directory.name -> name
is a symlink.- Commas are (unfortunately) not supported.
- Use quotes (
"name"
) for spaces, dots, etc.
Examples:
use fs_tree::{FsTree, tree, TrieMap};
let result = tree! {
file1
outer_dir: {
file2
inner_dir: {
file3
}
link1 -> target
link2 -> "/home/username/.gitconfig"
}
};
let expected = FsTree::Directory(TrieMap::from([
("file1".into(), FsTree::Regular),
("outer_dir".into(), FsTree::Directory(TrieMap::from([
("file2".into(), FsTree::Regular),
("inner_dir".into(), FsTree::Directory(TrieMap::from([
("file3".into(), FsTree::Regular),
]))),
("link1".into(), FsTree::Symlink("target".into())),
("link2".into(), FsTree::Symlink("/home/username/.gitconfig".into())),
]))),
]));
assert_eq!(result, expected);