Skip to main content

reifydb_testing/tempdir/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use std::{env, fs, path::Path};
5
6use uuid::Uuid;
7
8pub fn temp_dir<F>(f: F) -> std::io::Result<()>
9where
10	F: FnOnce(&Path) -> std::io::Result<()>,
11{
12	let mut path = env::temp_dir();
13	path.push(format!("reifydb-{}", Uuid::new_v4().to_string()));
14
15	fs::create_dir(&path)?;
16	let result = f(&path);
17
18	let _ = fs::remove_dir_all(&path);
19	result
20}