use std::io::{Read, Seek, SeekFrom, Write};
use tempfs::{TempFile, TempError};
fn main() -> Result<(), TempError> {
#[cfg(feature = "rand_gen")]
let mut temp_file = TempFile::new_random::<std::path::PathBuf>(None)?;
#[cfg(not(feature = "rand_gen"))]
let mut temp_file = TempFile::new("./tmp/hello.txt")?;
write!(temp_file, "Hello, temporary world!")?;
temp_file.seek(SeekFrom::Start(0))?;
let mut content = String::new();
temp_file.read_to_string(&mut content)?;
println!("Temp file content: {content}");
let _permanent_file = temp_file.persist_here("output.txt")?;
println!("Temporary file persisted as output.txt");
Ok(())
}