Skip to main content

turtle_build/infrastructure/
file_system.rs

1mod error;
2#[cfg(test)]
3mod fake;
4mod metadata;
5mod os;
6
7#[cfg(test)]
8pub use self::fake::FakeFileSystem;
9pub use self::{error::FileError, metadata::Metadata, os::OsFileSystem};
10use async_trait::async_trait;
11use std::path::Path;
12
13/// A file system.
14#[async_trait]
15pub trait FileSystem {
16    /// Reads a file.
17    async fn read_file(&self, path: &Path) -> Result<Vec<u8>, FileError>;
18    /// Reads a file into a string.
19    async fn read_file_to_string(&self, path: &Path) -> Result<String, FileError>;
20    /// Checks if a path exists.
21    async fn exists(&self, path: &Path) -> Result<bool, FileError>;
22    /// Returns metadata of a file if it exists.
23    async fn metadata(&self, path: &Path) -> Result<Option<Metadata>, FileError>;
24    /// Creates a directory and its ancestors.
25    async fn create_directory(&self, path: &Path) -> Result<(), FileError>;
26    /// Removes a file.
27    async fn remove_file(&self, path: &Path) -> Result<(), FileError>;
28}