ephemeral-dir

Crates.ioephemeral-dir
lib.rsephemeral-dir
version0.0.6
created_at2025-06-18 11:11:11.115984+00
updated_at2025-06-19 05:34:45.948988+00
descriptionA library for creating temporary directories that are auto-cleaned.
homepage
repositoryhttps://gitlab.com/shank/ephemeral-dir
max_upload_size
id1716953
size6,606
theshank (the-shank)

documentation

README

ephemeral-dir

Overview

The EphemeralDir struct allows you to create temporary directory that is automatically cleaned up (deleted) when the EphemeralDir instance goes out of scope. This is useful for tests or temporary file operations.

Why not tempfile?

tempfile, should be preferred as it is more complete. The reason for ephemeral_dir to exist is that I wanted to have temporary directory with a fixed name (without any random bytes in the name).

Usage

Use EphemeralDir::new(<path>) to create an ephemeral dir -- this would panic if the directory at <path> already exists.

Use EphemeralDir::new_forced(<path>) to create an ephemeral dir, deleting the existing directory at <path>.

use ephemeral_dir::EphemeralDir;
use std::path::Path;

fn main() -> eyre::Result<()> {
    let temp_path = Path::new("/tmp/my_temp_dir");
    let ep_dir = EphemeralDir::new(temp_path)?;
    // Directory "/tmp/my_temp_dir" now exists.

    // Do something with ep_dir.path()

    // When ep_dir goes out of scope, "/tmp/my_temp_dir" will be deleted.
    Ok(())
}
Commit count: 14

cargo fmt