Skip to main content

lgp/utils/
misc.rs

1use std::error::Error;
2use std::fs;
3use std::path::{Path, PathBuf};
4
5use crate::core::engines::reset_engine::{Reset, ResetEngine};
6
7pub type VoidResultAnyError = Result<(), Box<dyn Error>>;
8
9/// Create a path, optionally creating a file at the path.
10/// If `file` is true, creates the file; otherwise creates a directory.
11pub fn create_path(path: &str, file: bool) -> Result<PathBuf, Box<dyn Error>> {
12    let path = Path::new(path);
13
14    if let Some(parent) = path.parent() {
15        fs::create_dir_all(parent)?;
16    }
17
18    if file {
19        fs::File::create(path)?;
20    } else {
21        fs::create_dir_all(path)?;
22    }
23
24    Ok(path.to_owned())
25}
26
27impl Reset<uuid::Uuid> for ResetEngine {
28    fn reset(item: &mut uuid::Uuid) {
29        *item = uuid::Uuid::new_v4();
30    }
31}