pub fn tempdir() -> Result<TempDir>Expand description
Create a new temporary directory. Also see tempdir_in.
The tempdir function creates a directory in the file system and returns a
TempDir. The directory will be automatically deleted when the TempDir’s
destructor is run.
§Resource Leaking
See the resource leaking docs on TempDir.
§Security
Temporary directories are created with the default permissions unless otherwise
specified via Builder::permissions. Depending on your platform, this may make
them world-readable.
§Errors
If the directory can not be created, Err is returned.
§Examples
use tempfile::tempdir;
use std::fs::File;
use std::io::Write;
// Create a directory inside of `env::temp_dir()`
let tmp_dir = tempdir()?;
let file_path = tmp_dir.path().join("my-temporary-note.txt");
let mut tmp_file = File::create(file_path)?;
writeln!(tmp_file, "Brian was here. Briefly.")?;
// `tmp_dir` goes out of scope, the directory as well as
// `tmp_file` will be deleted here.
drop(tmp_file);
tmp_dir.close()?;