pub fn lower_with_reader(
src: &str,
file: &Path,
reader: &dyn ResourceReader,
) -> LowerResultExpand description
Parse, lower and resolve source using supplied external resource reads.
No filesystem reads occur unless reader performs them. Paths retain the same
source-relative resolution and portability checks as lower. Each resolved
path, including failures, is captured once in LowerResult::resources.
ยงExamples
use std::{io, path::Path};
use mos_eval::{ResourceData, lower_with_reader};
let reader = |path: &Path| {
if path == Path::new("project/refs.bib") {
Ok(ResourceData::new(b"@book{key, title={In memory}}".as_slice()))
} else {
Err(io::Error::from(io::ErrorKind::NotFound))
}
};
let result = lower_with_reader(
"#bibliography(\"refs.bib\")\nSee [@key]\n",
Path::new("project/main.mos"),
&reader,
);
assert!(!result.has_errors());
assert!(result.bibliography_complete);
assert!(result.resources.get(Path::new("project/refs.bib")).is_some());