Common/FileSystem/ReadDirectory.rs
1//! # ReadDirectory Effect
2//!
3//! Defines the `ActionEffect` for reading the contents of a directory.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::{DTO::FileTypeDTO::FileTypeDTO, FileSystemReader::FileSystemReader};
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will read the entries of a directory
11/// at the specified path.
12///
13/// It uses the `FileSystemReader` capability from the environment to perform
14/// the actual file I/O.
15///
16/// # Parameters
17/// * `Path`: The `PathBuf` of the directory to read.
18///
19/// # Returns
20/// An `ActionEffect` that resolves with a `Vec` of tuples, where each tuple
21/// contains the entry's name (`String`) and its `FileTypeDTO`.
22pub fn ReadDirectory(Path:PathBuf) -> ActionEffect<Arc<dyn FileSystemReader>, CommonError, Vec<(String, FileTypeDTO)>> {
23 ActionEffect::New(Arc::new(move |Reader:Arc<dyn FileSystemReader>| {
24 let PathClone = Path.clone();
25
26 Box::pin(async move { Reader.ReadDirectory(&PathClone).await })
27 }))
28}