Skip to main content

ensure_directory

Function ensure_directory 

Source
pub fn ensure_directory(path: &Path, dir_type: &str) -> Result<(), ProcessError>
Expand description

Ensures the specified directory exists, creating it if necessary.

§Arguments

  • path - The path of the directory to check.
  • dir_type - A label describing the directory type (e.g., “content”, “output”).

§Returns

  • Result<(), ProcessError> - Returns Ok if the directory exists or is successfully created.

§Errors

  • Returns ProcessError::DirectoryCreation if the directory cannot be created due to permissions or other issues.

§Examples

use ssg::process::ensure_directory;
use tempfile::tempdir;

let dir = tempdir().unwrap();
let new = dir.path().join("created");
ensure_directory(&new, "output").unwrap();
assert!(new.is_dir());