tempfile
Securely creates temporary files and directories in Rust with automatic cleanup on drop.
Official Documentation ↗v3.10. Check the official docs for the latest API surface.Installation
cargo add tempfileMethods
No methods match this filter.
tempfile creates unpredictable names and cleans up files and directories when handles drop.
Key Features
- Secure unpredictable file names
- Automatic deletion on drop
- Named and unnamed variants
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/tempfile/latest/tempfile/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:53.063Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- However TempDir and NamedTempFile will fail if their destructors don’t run. (https://docs.rs/tempfile/latest/tempfile/)
- Destructors may fail to run if the process exits through an unhandled signal interrupt (like SIGINT ), or if the instance is declared statically (like with lazy_static ), among other possible reasons. (https://docs.rs/tempfile/latest/tempfile/)
- The touch command would fail with an No such file or directory error. (https://docs.rs/tempfile/latest/tempfile/)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://docs.rs/tempfile/latest/tempfile/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:53.063Z.
- See the temporary file cleaner section for more security implications. (https://docs.rs/tempfile/latest/tempfile/)
- See the security documentation on the NamedTempFile and the TempDir types for more information. (https://docs.rs/tempfile/latest/tempfile/)
FAQ
- How do I keep a temporary file after the scope?
- Call persist with the destination path; otherwise the file is deleted when the handle drops.
- Are the names predictable?
- No. The crate generates random names to avoid symlink and race attacks on shared temp directories.
- Can it create temp files inside a directory?
- Yes. Use tempfile_in or Builder with a target directory such as a workspace-local tmp folder.
Report a problem with this API docOpens a pre-filled issue on GitHub.