Common/FileSystem/ReadFile.rs
1//! # ReadFile Effect
2//!
3//! Defines the `ActionEffect` for reading the entire content of a file.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::FileSystemReader::FileSystemReader;
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will read the entire contents of a
11/// file at the specified path into a byte vector.
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 file to read.
18///
19/// # Returns
20/// An `ActionEffect` that resolves with a `Vec<u8>` containing the file's
21/// content.
22pub fn ReadFile(Path:PathBuf) -> ActionEffect<Arc<dyn FileSystemReader>, CommonError, Vec<u8>> {
23 ActionEffect::New(Arc::new(move |Reader:Arc<dyn FileSystemReader>| {
24 let PathClone = Path.clone();
25
26 Box::pin(async move { Reader.ReadFile(&PathClone).await })
27 }))
28}