use crate::{Error, FilePath, FolderPath, StoragePath};
use std::io;
use tempfile::NamedTempFile;
impl StoragePath {
pub fn temp() -> Result<StoragePath, io::Error> {
let temp_file: NamedTempFile = NamedTempFile::new()?;
if let Some(path) = temp_file.path().to_str() {
Ok(StoragePath::parse(path)?)
} else {
Err(Error::path_not_utf8(temp_file.path()))
}
}
}
impl FilePath {
pub fn temp() -> Result<FilePath, io::Error> {
StoragePath::temp()?.to_file().map_err(Into::into)
}
}
impl FolderPath {
pub fn temp() -> Result<FolderPath, io::Error> {
Ok(StoragePath::temp()?.make_folder())
}
}