temp-file
Provides a TempFile
struct.
Features
- Makes a file in a system temporary directory
- Deletes the file on drop
- Optional name prefix, name suffix, contents, and directory.
- Depends only on
std
forbid(unsafe_code)
- 100% test coverage
Limitations
- Not security-hardened. See
Secure Programming for Linux and Unix HOWTO - 7.10. Avoid Race Conditions
and
mkstemp
. - Not tested on Windows.
Alternatives
tempfile
- Popular and mature
- Supports some security-sensitive use cases
- Contains
unsafe
, dependencies full ofunsafe
- Heavy dependencies (libc, winapi, rand, etc.)
test-temp-file
- Depends on crates which contain
unsafe
- Incomplete documentation
- Depends on crates which contain
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 = with_contents;
// Prints "/tmp/1a9b0".
println!;
assert_eq!;
// Prints "/tmp/1a9b1".
println!;
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.9
0/0 0/0 0/0 0/0 0/0
Changelog
- v0.1.9 -
AsRef<Path>
- v0.1.8 - Work when the file already exists.
- v0.1.7 - Add
in_dir
,with_suffix
, andTempFileBuilder
. - v0.1.6
- Return
std::io::Error
instead ofString
. - Add
cleanup
.
- Return
- v0.1.5 - Increase test coverage
- v0.1.4 - Add
leak
andpanic_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