std-function
tempfile::tempdir: disposable directory
Create an automatically managed temporary directory. Keep its owner alive while using paths inside it; close explicitly to observe cleanup errors. Drop cleanup is best effort. Expected stdout (not executed): sample Common mistake: Dropping TempDir before opening a file under its path.
Formal Syntax & Structure
rust syntaxrust
tempfile::tempdir() -> io::Result<TempDir>Working Example
Example Snippetrust
fn main() { let dir = tempfile::tempdir().unwrap(); let p = dir.path().join("note.txt"); std::fs::write(&p, b"sample").unwrap(); println!("{}", std::fs::read_to_string(&p).unwrap()); dir.close().unwrap();}