use std::{
path::{Path, PathBuf},
io::Read,
fs::File,
rc::Rc,
};
#[derive(Debug, PartialEq, Eq)]
pub struct Source {
pub contents: String,
pub path: PathBuf,
}
impl Source {
pub fn new(source: &str, path: &Path) -> Rc<Source> {
Rc::new(Source { contents: source.to_string(), path: path.to_owned() })
}
pub fn path(path: &Path) -> std::io::Result<Rc<Source>> {
let mut source = String::new();
let mut file = File::open(path)?;
file.read_to_string(&mut source)?;
Ok(Source::new(&source, path))
}
pub fn source(source: &str) -> Rc<Source> {
Source::new(&source.to_string(), &PathBuf::from("./source"))
}
}