Function std::env::temp_dir1.0.0[][src]

pub fn temp_dir() -> PathBuf

Returns the path of a temporary directory.

The temporary directory may be shared among users, or between processes with different privileges; thus, the creation of any files or directories in the temporary directory must use a secure method to create a uniquely named file. Creating a file or directory with a fixed or predictable name may result in "insecure temporary file" security vulnerabilities. Consider using a crate that securely creates temporary files or directories.


Returns the value of the TMPDIR environment variable if it is set, otherwise for non-Android it returns /tmp. If Android, since there is no global temporary folder (it is usually allocated per-app), it returns /data/local/tmp.


Returns the value of, in order, the TMP, TEMP, USERPROFILE environment variable if any are set and not the empty string. Otherwise, temp_dir returns the path of the Windows directory. This behavior is identical to that of GetTempPath, which this function uses internally.

use std::env;

fn main() {
    let mut dir = env::temp_dir();
    println!("Temporary directory: {}", dir.display());