Function tracing::stdlib::env::temp_dir

1.0.0 · source ·
pub fn temp_dir() -> PathBuf
Expand description

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.

§Platform-specific behavior

On Unix, returns the value of the TMPDIR environment variable if it is set, otherwise for non-Android it returns /tmp. On Android, since there is no global temporary folder (it is usually allocated per-app), it returns /data/local/tmp. On Windows, the behavior is equivalent to that of GetTempPath2 / GetTempPath, which this function uses internally. Note that, this may change in the future.

use std::env;

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