1b0fafea75
This commit adds a `Loader` type, which can be used to load multiple source strings. This was done to support the work on modules, but coincidentally enabled consolidating errors, since now `Config::run` can take a `&Loader`, and in the event of an error, return and `Error` that borrows from loaded strings. Multiple error types have been consolidated, and a bunch of ad-hoc error printing was removed.
22 lines
414 B
Rust
22 lines
414 B
Rust
use crate::common::*;
|
|
|
|
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))
|
|
}
|
|
}
|