use std::path::PathBuf; use crate::CONFIG; pub struct TempDir { path: PathBuf, } impl TempDir { pub fn new(path: PathBuf) -> TempDir { if !path.exists() { std::fs::create_dir_all(&path).unwrap(); } TempDir { path } } pub fn push>(&mut self, path: S) { self.path.push(path.into()); } } impl Default for TempDir { fn default() -> TempDir { TempDir::new({ if let Some(d) = CONFIG.with(|c| c.tmp_dir.clone()) { PathBuf::from(d) } else { PathBuf::from("/tmp/pkgr") } }) } } impl Into for TempDir { fn into(self) -> PathBuf { self.path } } impl Into for TempDir { fn into(self) -> String { self.path.to_str().unwrap().to_string() } } impl ToString for TempDir { fn to_string(&self) -> String { self.path.to_str().unwrap().to_string() } }