2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2021-07-26 01:26:06 -07:00
|
|
|
|
|
|
|
pub(crate) struct Loader {
|
|
|
|
arena: Arena<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Loader {
|
|
|
|
pub(crate) fn new() -> Self {
|
|
|
|
Loader {
|
|
|
|
arena: Arena::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn load<'src>(&'src self, path: &Path) -> RunResult<&'src str> {
|
|
|
|
let src = fs::read_to_string(path).map_err(|io_error| Error::Load {
|
|
|
|
path: path.to_owned(),
|
|
|
|
io_error,
|
|
|
|
})?;
|
|
|
|
Ok(self.arena.alloc(src))
|
|
|
|
}
|
|
|
|
}
|