Common/FileSystem/CreateFile.rs
1//! # CreateFile Effect
2//!
3//! Defines the `ActionEffect` for creating a new, empty file.
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, empty file at the
11/// specified path.
12///
13/// It uses the `FileSystemWriter` capability from the environment to perform
14/// the actual file I/O. This operation will typically fail if the file already
15/// exists, as it is not intended to overwrite.
16///
17/// # Parameters
18/// * `Path`: The `PathBuf` of the file to create.
19///
20/// # Returns
21/// An `ActionEffect` that resolves to `()` on success.
22pub fn CreateFile(Path:PathBuf) -> 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.CreateFile(&PathClone).await })
27 }))
28}