Skip to main content

Crate mod_tempdir

Crate mod_tempdir 

Source
Expand description

§mod-tempdir

Temporary directory management for Rust. Auto-cleanup on Drop, collision-resistant naming, cross-platform paths.

Designed as a tempfile replacement at MSRV 1.75. The default build has zero runtime dependencies outside std. An optional mod-rand feature swaps the built-in name mixer for mod_rand::tier2::unique_name, which produces a uniformly distributed name from a SplitMix + Stafford-finisher pipeline.

§Quick example

use mod_tempdir::TempDir;

let dir = TempDir::new().unwrap();
// ... use dir.path() to do work ...
// dir is automatically deleted when it goes out of scope

§Feature flags

  • mod-rand (off by default): use mod_rand::tier2::unique_name for directory naming. The alphabet is Crockford base32 on both paths, so any caller pattern-matching on the directory basename keeps working unchanged when the feature is toggled.

To enable in Cargo.toml:

mod-tempdir = { version = "0.9", features = ["mod-rand"] }

§Cleanup semantics

Drop::drop recursively removes the directory via std::fs::remove_dir_all. Failures during cleanup (file in use, permission denied, network filesystem hiccup) are intentionally silent: a Drop impl must not panic. Use TempDir::persist to keep the directory alive past drop if you need to inspect it.

Structs§

TempDir
A temporary directory that auto-deletes when dropped.