use chrono::Utc;
use std::path::PathBuf;
#[cfg_attr(test, mockall::automock)]
pub trait TempDirectoryProvider: Send + Sync {
fn temp_dir(&self) -> PathBuf;
}
pub struct TimestampTempDirectoryProvider {
temp_dir: PathBuf,
}
impl TimestampTempDirectoryProvider {
pub fn new(prefix: &str) -> Self {
let temp_dir = std::env::temp_dir().join(format!(
"mithril_client_{prefix}_{}",
Utc::now().timestamp_micros()
));
Self { temp_dir }
}
}
impl TempDirectoryProvider for TimestampTempDirectoryProvider {
fn temp_dir(&self) -> PathBuf {
self.temp_dir.clone()
}
}