pub fn create_temp_dir(tempdir_in: &Path) -> Result<TempDir, DatasetError>Expand description
Create a temporary directory under the given parent directory.
This is a small wrapper around tempfile::Builder used by dataset loaders to
keep intermediate download/extraction artifacts isolated. The created directory
is removed automatically when the returned tempfile::TempDir is dropped.
§Parameters
tempdir_in- The parent directory in which the temporary directory will be created.
§Errors
DatasetError- Returned if the temporary directory cannot be created.
§Example
use dataset_core::create_temp_dir;
use std::path::Path;
let parent_dir = "./temp_dir_example";
std::fs::create_dir_all(parent_dir).unwrap();
// Create a temporary directory
let temp_dir = create_temp_dir(Path::new(parent_dir)).unwrap();
let temp_path = temp_dir.path();
// Use the temporary directory for intermediate operations
let temp_file = temp_path.join("temp_file.txt");
std::fs::write(&temp_file, "temporary content").unwrap();
assert!(temp_file.exists());
// The temporary directory is automatically removed when `temp_dir` is dropped
drop(temp_dir);
// Clean up parent directory
std::fs::remove_dir_all(parent_dir).unwrap();