Enable dynamic access to the file access interface.
This commit is contained in:
parent
08eb59acd3
commit
a7330e38e4
@ -1,13 +1,15 @@
|
|||||||
|
use std::fmt::Debug;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub trait FileAccessInterface {
|
pub trait FileAccessInterface: Debug {
|
||||||
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>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct LocalFileAccessInterface;
|
pub struct LocalFileAccessInterface;
|
||||||
|
|
||||||
impl FileAccessInterface for 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)?)
|
Ok(std::fs::read_to_string(path)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,26 @@
|
|||||||
// use super::FileAccessInterface;
|
use super::FileAccessInterface;
|
||||||
// use super::LocalFileAccessInterface;
|
use super::LocalFileAccessInterface;
|
||||||
use crate::types::Object;
|
use crate::types::Object;
|
||||||
|
|
||||||
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
|
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
// , F: FileAccessInterface
|
|
||||||
pub struct GlobalSettings<'g, 's> {
|
pub struct GlobalSettings<'g, 's> {
|
||||||
pub radio_targets: Vec<&'g Vec<Object<'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> {
|
impl<'g, 's> GlobalSettings<'g, 's> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> GlobalSettings<'g, 's> {
|
||||||
GlobalSettings {
|
GlobalSettings {
|
||||||
radio_targets: Vec::new(),
|
radio_targets: Vec::new(),
|
||||||
// file_access: LocalFileAccessInterface,
|
file_access: &LocalFileAccessInterface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'g, 's> Default for GlobalSettings<'g, 's> {
|
impl<'g, 's> Default for GlobalSettings<'g, 's> {
|
||||||
fn default() -> Self {
|
fn default() -> GlobalSettings<'g, 's> {
|
||||||
GlobalSettings::new()
|
GlobalSettings::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user