Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Creating OS-dependent temporary directories in Rust

Rust Programming #temporary directory #crates #standard library #PathBuf

There are a few crates in Rust for retrieving system-dependent directories, such as the user’s home or the system configuration directory. The one I prefer is directories-next.

Recently, I needed a standard way to get the temporary directory. I checked the crate documentation but couldn’t find a proper function for this.

Then I noticed that std::env::temp_dir() returns a PathBuf pointing to the system’s temporary directory. This is a reminder to myself that we don’t always need extra packages for basic functionality.