Function from_yaml_file

Source
pub fn from_yaml_file(path: &PathBuf) -> Result<Tree, Error>
Expand description

Creates a file tree based on the content of a YAML file.

ยงErrors

Returns a Result containing the path to the root folder of the generated file tree on success, or an error if the operation fails.

Examples found in repository?
examples/yaml-file.rs (line 8)
4fn main() {
5    // Make sure to use the correct relative path to find the YAML file
6    let yaml_path = PathBuf::from("tests/fixtures/tree.yaml");
7
8    let tree = tree_fs::from_yaml_file(&yaml_path).expect("Failed to create tree from YAML file");
9
10    println!("--- Tree from YAML File Example ---");
11    println!("Tree created successfully from: {}", yaml_path.display());
12    println!("Root directory: {}", tree.root.display());
13    println!("Files created (check tests/fixtures/tree.yaml for full structure including a readonly file):");
14    println!("  - {}", tree.root.join("foo.json").display());
15    println!("  - {}", tree.root.join("folder/bar.yaml").display());
16    println!("  - {}", tree.root.join("readonly_config.ini").display());
17
18    // Optional: Verify read-only status if desired in an example
19    let readonly_path = tree.root.join("readonly_config.ini");
20    if readonly_path.exists() {
21        match fs::metadata(&readonly_path) {
22            Ok(metadata) => {
23                if metadata.permissions().readonly() {
24                    println!("Verified: {} is read-only.", readonly_path.display());
25                } else {
26                    println!(
27                        "Note: {} was expected to be read-only but isn't.",
28                        readonly_path.display()
29                    );
30                }
31            }
32            Err(e) => eprintln!(
33                "Could not get metadata for {}: {}",
34                readonly_path.display(),
35                e
36            ),
37        }
38    } else {
39        eprintln!("File not found: {}", readonly_path.display());
40    }
41}