API Reference

tempfile

Securely creates temporary files and directories in Rust with automatic cleanup on drop.

Official Documentation ↗
CompatibilityThis documentation covers version v3.10. Check the official docs for the latest API surface.

Installation

cargocargo add tempfile

Methods

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.

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.

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.