use std::path::PathBuf; use std::{env, fs}; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; pub fn temp_file_path() -> PathBuf { let temp_dir = env::temp_dir(); let rand_string: String = thread_rng() .sample_iter(&Alphanumeric) .take(30) .map(char::from) .collect(); temp_dir.join(rand_string) } pub fn write_to_temp_file(content: &str) -> PathBuf { let file = temp_file_path(); fs::write(&file, content).unwrap(); file }