Crate temp_file[][src]

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

temp-file

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

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

Changelog

  • 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

Happy Contributors 🙂

Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:

  • Always respond within 24 hours
  • Provide clear & concrete feedback
  • Immediately make a new release for your accepted change

Structs

TempFile

The path of an existing writable file in a system temporary directory.

Functions

empty

Create a new empty file in a system temporary directory.

with_contents

Create a new file in a system temporary directory and writes contents to it.