8 releases

0.1.7 Mar 23, 2022
0.1.6 Apr 28, 2021
0.1.5 Mar 23, 2021

#311 in Filesystem

Download history 999/week @ 2023-08-11 1269/week @ 2023-08-18 1248/week @ 2023-08-25 1382/week @ 2023-09-01 1501/week @ 2023-09-08 1413/week @ 2023-09-15 1432/week @ 2023-09-22 1138/week @ 2023-09-29 1303/week @ 2023-10-06 1248/week @ 2023-10-13 1409/week @ 2023-10-20 1890/week @ 2023-10-27 1583/week @ 2023-11-03 1972/week @ 2023-11-10 2235/week @ 2023-11-17 1402/week @ 2023-11-24

7,492 downloads per month
Used in 15 crates (14 directly)

Apache-2.0

16KB
151 lines

temp-file

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

Provides a TempFile struct.

Features

  • Makes a file in a system temporary directory
  • Deletes the file on drop
  • Optional file name prefix
  • Optional file contents
  • Depends only on std
  • forbid(unsafe_code)
  • 100% test coverage

Limitations

Alternatives

  • tempfile
    • Popular and mature
    • Supports some security-sensitive use cases
    • Contains unsafe, dependencies full of unsafe
    • Heavy dependencies (libc, winapi, rand, etc.)
  • test-temp-file
    • Depends on crates which contain unsafe
    • Incomplete documentation
  • temp_file_name
    • Does not delete file
    • Usage is not straightforward. Missing example.
  • mktemp
    • Sets file mode 0600 on unix
    • Contains unsafe
    • No readme or online docs

Related Crates

Example

let t = temp_file::with_contents(b"abc");
// Prints "/tmp/1a9b0".
println!("{:?}", t.path());
assert_eq!(
  "abc",
  std::fs::read_to_string(t.path()).unwrap(),
);
// Prints "/tmp/1a9b1".
println!("{:?}", temp_file::empty().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-file 0.1.7

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

Changelog

  • v0.1.7 - Add in_dir, with_suffix, and TempFileBuilder.
  • v0.1.6
    • Return std::io::Error instead of String.
    • Add cleanup.
  • v0.1.5 - Increase test coverage
  • v0.1.4 - Add leak and panic_on_cleanup_error.
  • v0.1.3 - Update docs
  • v0.1.2 - Update example
  • v0.1.1 - Minor code cleanup, update docs
  • v0.1.0 - Initial version

License: Apache-2.0

No runtime deps