Expand description
§temp-dir-builder 
Oftentimes, testing scenarios involve interactions with the file system. temp-dir-builder provides a convenient solution for creating file system trees tailored to the needs of your tests. This library offers:
- An easy way to generate a tree with recursive paths.
- Tree creation within a temporary folder.
- The ability to create a tree using a builder.
§Usage
With the builder API, you can define file paths and contents in a structured way. Here’s how to create a tree with the builder:
When the temp_dir instance is dropped, the temporary folder and its contents are automatically deleted, which is particularly useful for tests that require a clean state.
use temp_dir_builder::TempDirectoryBuilder;
let temp_dir = TempDirectoryBuilder::default()
.add_text_file("test/foo.txt", "bar")
.add_binary_file("test/foo2.txt", &[98u8, 97u8, 114u8])
.add_empty_file("test/folder-a/folder-b/bar.txt")
.add_file("test/file.rs", file!())
.add_directory("test/dir")
.build()
.expect("create temp dir");
println!("created successfully in {}", temp_dir.path().display());§Credits
This is a fork of tree-fs I heavily rewritten, original idea by Elad Kaplan.
Structs§
- Temp
Directory - Represents a temporary directory.
By default this temporary directory is deleted when this struct is dropped. - Temp
Directory Builder - A temporary directory builder that contains a list of entries to be created.
Enums§
- Build
Error - Error happening when creating the directory tree.