Crates.io | ephemeral-dir |
lib.rs | ephemeral-dir |
version | 0.0.6 |
created_at | 2025-06-18 11:11:11.115984+00 |
updated_at | 2025-06-19 05:34:45.948988+00 |
description | A library for creating temporary directories that are auto-cleaned. |
homepage | |
repository | https://gitlab.com/shank/ephemeral-dir |
max_upload_size | |
id | 1716953 |
size | 6,606 |
ephemeral-dir
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.
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).
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(())
}