Skip to main content

load_indexed_in

Function load_indexed_in 

Source
pub fn load_indexed_in(
    root: &SourceRoot,
    options: &LoadOptions,
    overlay: &Overlay,
) -> Result<(World, ReferenceIndex), Vec<Diagnostic>>
Expand description

Loads the tree of an opened root as load_edited_in does, and also returns the index of its references: every reference the loader checks or follows, with its target, role, holder, file and span (see index). The world, and on failure the diagnostics, are those load_edited_in gives, with one exception: a tree whose index would be too large to number is refused (see below).

Indexing costs memory in proportion to the references, about 36 bytes each plus their distinct strings, and some time to sort them; the other loads record nothing. Recording stops at the load’s first diagnostic, as the load then fails, so a broken tree costs about what a plain load of it does. A tree with more references, distinct strings or holders than 32 bits number is refused with a source.budget diagnostic, which only an indexed load gives.

use tilewright_source::{LoadOptions, Overlay, SourceRoot, index::Target};

let root = SourceRoot::new(std::path::Path::new("content"));
let (_, index) = tilewright_source::load_indexed_in(&root, &LoadOptions::default(), &Overlay::new())
    .map_err(|diagnostics| diagnostics.len())?;
for reference in index.to(Target::Definition { kind: "proto", id: "tree" }) {
    println!("{} {:?} {:?}", reference.file(), reference.span(), reference.role());
}

§Errors

Returns every diagnostic found, sorted by path and position, as load_edited_in does; or, for a tree that otherwise loads but whose references, distinct strings or holders are too many to number, one source.budget diagnostic at ..