Enable dynamic access to the file access interface.

This commit is contained in:
Tom Alexander
2023-09-04 16:29:41 -04:00
parent 08eb59acd3
commit a7330e38e4
2 changed files with 11 additions and 10 deletions

View File

@@ -1,13 +1,15 @@
use std::fmt::Debug;
use std::path::Path;
pub trait FileAccessInterface {
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<String, Box<dyn std::error::Error>>;
pub trait FileAccessInterface: Debug {
fn read_file(&self, path: &dyn AsRef<Path>) -> Result<String, Box<dyn std::error::Error>>;
}
#[derive(Debug, Clone)]
pub struct LocalFileAccessInterface;
impl FileAccessInterface for LocalFileAccessInterface {
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<String, Box<dyn std::error::Error>> {
fn read_file(&self, path: &dyn AsRef<Path>) -> Result<String, Box<dyn std::error::Error>> {
Ok(std::fs::read_to_string(path)?)
}
}