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
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
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)?)
}
}

View File

@ -1,27 +1,26 @@
// use super::FileAccessInterface;
// use super::LocalFileAccessInterface;
use super::FileAccessInterface;
use super::LocalFileAccessInterface;
use crate::types::Object;
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
#[derive(Debug, Clone)]
// , F: FileAccessInterface
pub struct GlobalSettings<'g, 's> {
pub radio_targets: Vec<&'g Vec<Object<'s>>>,
// pub file_access: F,
pub file_access: &'g dyn FileAccessInterface,
}
impl<'g, 's> GlobalSettings<'g, 's> {
pub fn new() -> Self {
pub fn new() -> GlobalSettings<'g, 's> {
GlobalSettings {
radio_targets: Vec::new(),
// file_access: LocalFileAccessInterface,
file_access: &LocalFileAccessInterface,
}
}
}
impl<'g, 's> Default for GlobalSettings<'g, 's> {
fn default() -> Self {
fn default() -> GlobalSettings<'g, 's> {
GlobalSettings::new()
}
}