use std::{fs}; pub struct CodeSrc { path: String, src: String, } impl CodeSrc { pub fn new(path: &String) -> Result { Ok(Self { path: path.to_owned(), src: Self::read_code(path)?, }) } fn read_code(path: &String) -> Result { let result = fs::read_to_string(path); // read the source if let Ok(src) = result { return Ok(src); } Err(format!("unable to fetch source code from {}: {}", path, result.err().unwrap())) } pub fn code(&self) -> &String { &self.src } pub fn path(&self) -> &String { &self.path } }