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.
Note that the returned value may be a symbolic link, not a directory.
On Unix, returns the value of the TMPDIR environment variable if it is set, otherwise the value is OS-specific:
/data/local/tmp otherwise.confstr(_CS_DARWIN_USER_TEMP_DIR, ...), as recommended by Apple’s security guidelines./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());
}
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/env/fn.temp_dir.html