Common/FileSystem/
CreateDirectory.rs

1//! # CreateDirectory Effect
2//!
3//! Defines the `ActionEffect` for creating a new directory.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::FileSystemWriter::FileSystemWriter;
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will create a new directory at the
11/// specified path.
12///
13/// It uses the `FileSystemWriter` capability from the environment to perform
14/// the actual file I/O.
15///
16/// # Parameters
17/// * `Path`: The `PathBuf` of the directory to create.
18/// * `Recursive`: If `true`, creates all parent directories as needed.
19///
20/// # Returns
21/// An `ActionEffect` that resolves to `()` on success.
22pub fn CreateDirectory(Path:PathBuf, Recursive:bool) -> ActionEffect<Arc<dyn FileSystemWriter>, CommonError, ()> {
23	ActionEffect::New(Arc::new(move |Writer:Arc<dyn FileSystemWriter>| {
24		let PathClone = Path.clone();
25
26		Box::pin(async move { Writer.CreateDirectory(&PathClone, Recursive).await })
27	}))
28}