basic/basic.rs
1//! Minimal example: create a temp directory, write a file, observe auto-cleanup.
2//!
3//! Run with: `cargo run --example basic`
4
5use mod_tempdir::TempDir;
6
7fn main() -> std::io::Result<()> {
8 let dir = TempDir::new()?;
9 println!("Created: {}", dir.path().display());
10
11 let file = dir.path().join("greeting.txt");
12 std::fs::write(&file, b"Hello from mod-tempdir!\n")?;
13 println!("Wrote: {}", file.display());
14
15 println!("Contents: {}", std::fs::read_to_string(&file)?);
16 println!("\n(directory will be deleted automatically when this program exits)");
17
18 Ok(())
19}