use std::{
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: PathBuf) -> Rc<Source> {
Rc::new(Source { contents: source.to_string(), path })
}
pub fn path(path: PathBuf) -> std::io::Result<Rc<Source>> {
let mut source = String::new();
let mut file = File::open(path.clone())?;
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"))
}
}