Common/FileSystem/Rename.rs
1//! # Rename Effect
2//!
3//! Defines the `ActionEffect` for renaming or moving a file or 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 rename (or move) a file or
11/// directory from a source path to a target path.
12///
13/// It uses the `FileSystemWriter` capability from the environment to perform
14/// the actual file I/O.
15///
16/// # Parameters
17/// * `Source`: The `PathBuf` of the file or directory to rename.
18/// * `Target`: The `PathBuf` of the new name or location.
19/// * `Overwrite`: If `true`, an existing file or directory at the target path
20/// will be overwritten.
21///
22/// # Returns
23/// An `ActionEffect` that resolves to `()` on success.
24pub fn Rename(
25 Source:PathBuf,
26
27 Target:PathBuf,
28
29 Overwrite:bool,
30) -> ActionEffect<Arc<dyn FileSystemWriter>, CommonError, ()> {
31 ActionEffect::New(Arc::new(move |Writer:Arc<dyn FileSystemWriter>| {
32 let SourceClone = Source.clone();
33
34 let TargetClone = Target.clone();
35
36 Box::pin(async move { Writer.Rename(&SourceClone, &TargetClone, Overwrite).await })
37 }))
38}