2023-10-14 22:39:43 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
pub struct TempDir {
|
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TempDir {
|
|
|
|
pub fn new(path: PathBuf) -> TempDir {
|
|
|
|
if !path.exists() {
|
|
|
|
std::fs::create_dir_all(&path).unwrap();
|
|
|
|
}
|
2023-10-14 22:39:44 +02:00
|
|
|
TempDir { path }
|
2023-10-14 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn push<S: Into<String>>(&mut self, path: S) {
|
|
|
|
self.path.push(path.into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TempDir {
|
|
|
|
fn default() -> TempDir {
|
|
|
|
TempDir::new({
|
|
|
|
let mut t = std::env::temp_dir();
|
|
|
|
t.push("pkgr");
|
|
|
|
t
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<PathBuf> for TempDir {
|
|
|
|
fn into(self) -> PathBuf {
|
|
|
|
self.path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<String> 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()
|
|
|
|
}
|
2023-10-14 22:39:44 +02:00
|
|
|
}
|