rune/workspace/
source_loader.rsuse std::path::Path;
use crate::ast::Span;
use crate::compile::WithSpan;
use crate::workspace::WorkspaceError;
use crate::Source;
use super::WorkspaceErrorKind;
pub trait SourceLoader {
fn load(&mut self, span: Span, path: &Path) -> Result<Source, WorkspaceError>;
}
#[derive(Default)]
pub struct FileSourceLoader {}
impl FileSourceLoader {
pub fn new() -> Self {
Self::default()
}
}
impl SourceLoader for FileSourceLoader {
fn load(&mut self, span: Span, path: &Path) -> Result<Source, WorkspaceError> {
match Source::from_path(path) {
Ok(source) => Ok(source),
Err(error) => Err(WorkspaceError::new(
span,
WorkspaceErrorKind::Source {
path: path.try_into().with_span(span)?,
error,
},
)),
}
}
}