pub fn tempfile_in<P: AsRef<Path>>(dir: P) -> Result<File>
Expand description

Create a new temporary file in the specified directory.

This method accepts AsRef<Path> rather than AsRef<Utf8Path> because it returns a std::fs::File.

Security

This variant is secure/reliable in the presence of a pathological temporary file cleaner. If the temporary file isn’t created in std::env::temp_dir() then temporary file cleaners aren’t an issue.

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 camino_tempfile::tempfile_in;
use std::io::{self, Write};

// Create a file inside of the current working directory
let mut file = tempfile_in("./")?;

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