file_storage/path/construct/
temp.rs1use crate::{Error, FilePath, FolderPath, StoragePath};
2use std::io;
3use tempfile::NamedTempFile;
4
5impl StoragePath {
6 pub fn temp() -> Result<StoragePath, io::Error> {
10 let temp_file: NamedTempFile = NamedTempFile::new()?;
11 if let Some(path) = temp_file.path().to_str() {
12 Ok(StoragePath::parse(path)?)
13 } else {
14 Err(Error::path_not_utf8(temp_file.path()))
15 }
16 }
17}
18
19impl FilePath {
20 pub fn temp() -> Result<FilePath, io::Error> {
24 StoragePath::temp()?.to_file().map_err(Into::into)
25 }
26}
27
28impl FolderPath {
29 pub fn temp() -> Result<FolderPath, io::Error> {
33 Ok(StoragePath::temp()?.make_folder())
34 }
35}