Common/FileSystem/
FileSystemReader.rs

1//! # FileSystemReader Trait
2//!
3//! Defines the abstract service trait for read-only filesystem capabilities.
4
5use std::path::PathBuf;
6
7use async_trait::async_trait;
8
9use super::DTO::{FileSystemStatDTO::FileSystemStatDTO, FileTypeDTO::FileTypeDTO};
10use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
11
12/// An abstract service contract for an environment component that can perform
13/// read-only filesystem operations.
14///
15/// This trait is implemented by `MountainEnvironment` and typically uses
16/// `tokio::fs` to fulfill the contract. Separating read operations from write
17/// operations allows for more granular and secure dependency injection, as
18/// some parts of the application may only need read access.
19#[async_trait]
20pub trait FileSystemReader: Environment + Send + Sync {
21	/// Reads the entire content of a file into a byte vector.
22	///
23	/// # Parameters
24	/// * `Path`: The `PathBuf` of the file to read.
25	///
26	/// # Returns
27	/// A `Result` containing the file's content as `Vec<u8>`.
28	async fn ReadFile(&self, Path:&PathBuf) -> Result<Vec<u8>, CommonError>;
29
30	/// Reads metadata for a file or directory.
31	///
32	/// # Parameters
33	/// * `Path`: The `PathBuf` of the file or directory to stat.
34	///
35	/// # Returns
36	/// A `Result` containing the `FileSystemStatDTO` metadata.
37	async fn StatFile(&self, Path:&PathBuf) -> Result<FileSystemStatDTO, CommonError>;
38
39	/// Reads the entries of a directory.
40	///
41	/// # Parameters
42	/// * `Path`: The `PathBuf` of the directory to read.
43	///
44	/// # Returns
45	/// A `Result` containing a vector of tuples, where each tuple is
46	/// `(entry_name, entry_file_type)`.
47	async fn ReadDirectory(&self, Path:&PathBuf) -> Result<Vec<(String, FileTypeDTO)>, CommonError>;
48}