temp-dir-builder 0.1.0

Provides a convenient way to create a temporary directory containing files
Documentation
  • Coverage
  • 52.17%
    12 out of 23 items documented2 out of 13 items with examples
  • Size
  • Source code size: 35.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 28s Average build duration of successful builds.
  • all releases: 28s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • IohannRabeson

temp-dir-builder CI

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.