Function tempfile::file::tempfile

source ·
pub fn tempfile() -> Result<File>
Expand description

Create a new temporary file.

The file will be created in the location returned by env::temp_dir().

§Security

This variant is secure/reliable in the presence of a pathological temporary file cleaner.

§Resource Leaking

The temporary file will be automatically removed by the OS when the last handle to it is closed. This doesn’t rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file.

§Errors

If the file can not be created, Err is returned.

§Examples

use tempfile::tempfile;
use std::io::Write;

// Create a file inside of `env::temp_dir()`.
let mut file = tempfile()?;

writeln!(file, "Brian was here. Briefly.")?;