Public API and docs

This commit is contained in:
2023-05-26 15:23:15 +01:00
parent 3c1a6e2be2
commit fdf18e6ff8
99 changed files with 503 additions and 406 deletions

View File

@@ -1,3 +1,4 @@
//! File system implementation of the source loader callback
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::{fs, io};
@@ -9,6 +10,7 @@ use crate::pipeline::error::{
use crate::utils::iter::box_once;
use crate::utils::{BoxedIter, Cache};
/// All the data available about a failed source load call
#[derive(Debug)]
pub struct FileLoadingError {
file: io::Error,
@@ -40,10 +42,9 @@ impl Loaded {
}
}
/// Returned by any source loading callback
pub type IOResult = Result<Loaded, Rc<dyn ProjectError>>;
pub type FileCache<'a> = Cache<'a, Sym, IOResult>;
/// Load a file from a path expressed in Rust strings, but relative to
/// a root expressed as an OS Path.
pub fn load_file(root: &Path, path: &[impl AsRef<str>]) -> IOResult {
@@ -81,7 +82,7 @@ pub fn load_file(root: &Path, path: &[impl AsRef<str>]) -> IOResult {
}
/// Generates a cached file loader for a directory
pub fn mk_cache(root: PathBuf, i: &Interner) -> FileCache {
pub fn mk_cache(root: PathBuf, i: &Interner) -> Cache<Sym, IOResult> {
Cache::new(move |token: Sym, _this| -> IOResult {
let path = i.r(token).iter().map(|t| i.r(*t).as_str()).collect::<Vec<_>>();
load_file(&root, &path)