| Crates.io | temp-dir-builder |
| lib.rs | temp-dir-builder |
| version | 0.1.0 |
| created_at | 2025-04-14 17:28:18.052245+00 |
| updated_at | 2025-04-14 17:28:18.052245+00 |
| description | Provides a convenient way to create a temporary directory containing files |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1633100 |
| size | 36,093 |
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:
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());
This is a fork of tree-fs I heavily rewritten, original idea by Elad Kaplan.