1use std::io::{Read, Seek, SeekFrom, Write};
2use tempfs::{TempFile, TempError};
3
4fn main() -> Result<(), TempError> {
5 #[cfg(feature = "rand_gen")]
7 let mut temp_file = TempFile::new_random::<std::path::PathBuf>(None)?;
8 #[cfg(not(feature = "rand_gen"))]
9 let mut temp_file = TempFile::new("./tmp/hello.txt")?;
10
11 write!(temp_file, "Hello, temporary world!")?;
13
14 temp_file.seek(SeekFrom::Start(0))?;
16
17 let mut content = String::new();
19 temp_file.read_to_string(&mut content)?;
20 println!("Temp file content: {content}");
21
22 let _permanent_file = temp_file.persist_here("output.txt")?;
25 println!("Temporary file persisted as output.txt");
26
27 Ok(())
28}