15 releases

0.1.14 Oct 3, 2024
0.1.13 Mar 22, 2024
0.1.12 Dec 22, 2023
0.1.11 Apr 28, 2021
0.1.10 Mar 23, 2021

#34 in Filesystem

Download history 31255/week @ 2024-08-06 26340/week @ 2024-08-13 27872/week @ 2024-08-20 28046/week @ 2024-08-27 33379/week @ 2024-09-03 36876/week @ 2024-09-10 40273/week @ 2024-09-17 39962/week @ 2024-09-24 35624/week @ 2024-10-01 36119/week @ 2024-10-08 35463/week @ 2024-10-15 33686/week @ 2024-10-22 33877/week @ 2024-10-29 29516/week @ 2024-11-05 26515/week @ 2024-11-12 21577/week @ 2024-11-19

116,164 downloads per month
Used in 132 crates (94 directly)

Apache-2.0

17KB
97 lines

temp-dir

crates.io version license: Apache 2.0 unsafe forbidden pipeline status

Provides a TempDir struct.

Features

  • Makes a directory in a system temporary directory
  • Recursively deletes the directory and its contents on drop
  • Deletes symbolic links and does not follow them
  • Optional name prefix
  • Depends only on std
  • forbid(unsafe_code)
  • 100% test coverage

Limitations

Alternatives

  • tempdir
    • Unmaintained
    • Popular and mature
    • Heavy dependencies (rand, winapi)
  • tempfile
    • Popular and mature
    • Contains unsafe, dependencies full of unsafe
    • Heavy dependencies (libc, winapi, rand, etc.)
  • test_dir
    • Has a handy TestDir struct
    • Incomplete documentation
  • temp_testdir
    • Incomplete documentation
  • mktemp
    • Sets directory mode 0700 on unix
    • Contains unsafe
    • No readme or online docs

Related Crates

Example

use temp_dir::TempDir;
let d = TempDir::new().unwrap();
// Prints "/tmp/t1a9b-0".
println!("{:?}", d.path());
let f = d.child("file1");
// Prints "/tmp/t1a9b-0/file1".
println!("{:?}", f);
std::fs::write(&f, b"abc").unwrap();
assert_eq!(
    "abc",
    std::fs::read_to_string(&f).unwrap(),
);
// Prints "/tmp/t1a9b-1".
println!(
    "{:?}", TempDir::new().unwrap().path());

Cargo Geiger Safety Report


Metric output format: x/y
    x = unsafe code used by the build
    y = total unsafe code found in the crate

Symbols: 
    🔒  = No `unsafe` usage found, declares #![forbid(unsafe_code)]= No `unsafe` usage found, missing #![forbid(unsafe_code)]
    ☢️  = `unsafe` usage found

Functions  Expressions  Impls  Traits  Methods  Dependency

0/0        0/0          0/0    0/0     0/0      🔒  temp-dir 0.1.14

0/0        0/0          0/0    0/0     0/0    

Changelog

  • v0.1.14 - AsRef<Path>
  • v0.1.13 - Update docs.
  • v0.1.12 - Work when the directory already exists.
  • v0.1.11
    • Return std::io::Error instead of String.
    • Add cleanup.
  • v0.1.10 - Implement Eq, Ord, Hash
  • v0.1.9 - Increase test coverage
  • v0.1.8 - Add leak.
  • v0.1.7 - Update docs: Warn about std::fs::remove_dir_all being unreliable on Windows. Warn about predictable directory and file names. Thanks to Reddit user burntsushi.
  • v0.1.6 - Add TempDir::panic_on_cleanup_error. Thanks to Reddit users KhorneLordOfChaos and dpc_pw for their comments.
  • v0.1.5 - Explain how it handles symbolic links. Thanks to Reddit user Mai4eeze for this idea.
  • v0.1.4 - Update docs
  • v0.1.3 - Minor code cleanup, update docs
  • v0.1.2 - Update docs
  • v0.1.1 - Fix license
  • v0.1.0 - Initial version

License: Apache-2.0

No runtime deps