pub fn tempfile_in<P: AsRef<Path>>(dir: P) -> Result<File>
Expand description
Create a new temporary file in the specified directory.
§Security
This variant is secure/reliable in the presence of a pathological temporary file cleaner.
If the temporary file isn’t created in 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 tempfile::tempfile_in;
use std::io::Write;
// Create a file inside of the current working directory
let mut file = tempfile_in("./")?;
writeln!(file, "Brian was here. Briefly.")?;