Introduce a file access interface for reading additional files.
This commit is contained in:
		
							parent
							
								
									a8f277efe5
								
							
						
					
					
						commit
						da1ce2717d
					
				
							
								
								
									
										13
									
								
								src/context/file_access_interface.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/context/file_access_interface.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| use std::path::Path; | ||||
| 
 | ||||
| pub trait FileAccessInterface { | ||||
|     fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<String, Box<dyn std::error::Error>>; | ||||
| } | ||||
| 
 | ||||
| pub struct LocalFileAccessInterface; | ||||
| 
 | ||||
| impl FileAccessInterface for LocalFileAccessInterface { | ||||
|     fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<String, Box<dyn std::error::Error>> { | ||||
|         Ok(std::fs::read_to_string(path)?) | ||||
|     } | ||||
| } | ||||
| @ -1,16 +1,20 @@ | ||||
| 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)] | ||||
| pub struct GlobalSettings<'g, 's> { | ||||
| pub struct GlobalSettings<'g, 's, F: FileAccessInterface> { | ||||
|     pub radio_targets: Vec<&'g Vec<Object<'s>>>, | ||||
|     pub file_access: F, | ||||
| } | ||||
| 
 | ||||
| impl<'g, 's> GlobalSettings<'g, 's> { | ||||
|     pub fn new() -> Self { | ||||
|         GlobalSettings { | ||||
|             radio_targets: Vec::new(), | ||||
|             file_access: LocalFileAccessInterface, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -2,6 +2,7 @@ use crate::error::Res; | ||||
| use crate::parser::OrgSource; | ||||
| 
 | ||||
| mod exiting; | ||||
| mod file_access_interface; | ||||
| mod global_settings; | ||||
| mod list; | ||||
| mod parser_context; | ||||
| @ -18,6 +19,8 @@ pub trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s | ||||
| pub type DynMatcher<'c> = dyn Matcher + 'c; | ||||
| 
 | ||||
| pub use exiting::ExitClass; | ||||
| pub use file_access_interface::FileAccessInterface; | ||||
| pub use file_access_interface::LocalFileAccessInterface; | ||||
| pub use global_settings::GlobalSettings; | ||||
| pub use list::List; | ||||
| pub use parser_context::Context; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander