pub trait Loader {
// Required method
fn load(&self, name: &str) -> Result<Vec<(String, String)>, String>;
// Provided methods
fn entry_package(&self, _path: &Path) -> Option<String> { ... }
fn needs(
&self,
_package: &str,
_entry_dir: Option<&Path>,
) -> Option<BTreeSet<String>> { ... }
fn version(
&self,
_package: &str,
_entry_dir: Option<&Path>,
) -> Option<String> { ... }
fn parse(&self, src: &str) -> Result<Vec<Spanned>, ParseError> { ... }
fn available(&self) -> Vec<String> { ... }
fn frontend(&self, _entry: &Path) -> Option<Frontend> { ... }
}Expand description
Supplies the source of a named bidama.
One method, because resolution needs exactly one thing: given a name, the blue source that name refers to. Where it came from — a working tree, a nix store path, a git object, memory — is the implementation’s business and deliberately invisible here.
Required Methods§
Sourcefn load(&self, name: &str) -> Result<Vec<(String, String)>, String>
fn load(&self, name: &str) -> Result<Vec<(String, String)>, String>
The .b sources of name, as (label, source) pairs.
The label is for diagnostics only; nothing keys on it. A package with
several files returns several pairs, and their relative order is the
implementation’s to fix — FsLoader
sorts by filename so a load is reproducible rather than
directory-order-dependent.
Err is a human-readable reason the package could not be loaded. It
must name what was looked for, because “package not found” without a
name sends the reader grepping a distribution to find which one.
Provided Methods§
Sourcefn entry_package(&self, _path: &Path) -> Option<String>
fn entry_package(&self, _path: &Path) -> Option<String>
The bidama an ENTRY file at path belongs to, if it belongs to one:
the package(name, …) of the Bluefile beside it. blue test bidamas/retsu/retsu.b checks and runs retsu’s own definitions, under
retsu’s namespace, exactly as an importer sees them.
A file with no bidama around it (a script, spec/*.b) is in the root
namespace, and so is every entry a loader without a filesystem is
handed, which is this default.
Sourcefn needs(
&self,
_package: &str,
_entry_dir: Option<&Path>,
) -> Option<BTreeSet<String>>
fn needs( &self, _package: &str, _entry_dir: Option<&Path>, ) -> Option<BTreeSet<String>>
The bidamas package’s Bluefile.lock records as needs (with no lock,
its Bluefile’s rows), when the loader can read it.
None when it cannot, and the check stage then has nothing to compare
the package’s use forms against (B0019).
entry_dir is the directory of the entry file, for the entry’s own
bidama, which a loader may not find under its roots.
Sourcefn version(&self, _package: &str, _entry_dir: Option<&Path>) -> Option<String>
fn version(&self, _package: &str, _entry_dir: Option<&Path>) -> Option<String>
Bidama package’s Bluefile version, when the loader can read it —
what a legacy_names window is measured against.
Sourcefn parse(&self, src: &str) -> Result<Vec<Spanned>, ParseError>
fn parse(&self, src: &str) -> Result<Vec<Spanned>, ParseError>
The spanned tree of one source this loader handed out, or of the entry. Resolution parses through here, so a loader that has seen a text before (an editor’s session) can answer without parsing it again.
§Errors
The parser’s, unchanged.
Sourcefn available(&self) -> Vec<String>
fn available(&self) -> Vec<String>
Every bidama this loader could load, by name, when it can enumerate
them: what an editor offers behind a use the file does not have yet.
fn frontend(&self, _entry: &Path) -> Option<Frontend>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".