pub fn directory(dir: &Path, name: &str) -> Result<(), String>
Expand description
Ensures a directory exists, creating it if necessary.
This function takes a reference to a Path
object for a directory and a
human-readable name for the directory, and creates the directory if it
does not already exist.
§Arguments
dir
- A reference to aPath
object for the directory.name
- A human-readable name for the directory, used in error messages.
§Returns
Result<(), String>
- A result indicating success or failure.Ok(())
if the directory exists or was created successfully.Err(String)
if the directory does not exist and could not be created.
§Example
use serde_yml::utilities::directory::directory;
use std::path::Path;
let dir = Path::new("logs");
match directory(dir, "logs") {
Ok(()) => println!("Logs directory created successfully!"),
Err(e) => eprintln!("{}", e),
}