pub struct LoaderDocument { /* private fields */ }Expand description
A template loader document: exactly what to render, stated by a caller.
{"reference": "<string>", "entry": "<name>", "search_path": ["<absolute dir>"],
"templates": [{"name": "<name>", "source": "<text>"}], "digest": "sha256:<hex>"}reference is what an item rendered from it records as its provenance template,
verbatim; entry is loaded over the search_path directories and then the templates
pairs, as a TemplateLoader searches; and digest, when present, must be the digest
that chain computes. Every other key is ignored.
Implementations§
Source§impl LoaderDocument
impl LoaderDocument
Sourcepub const KEYS: [&'static str; 5]
pub const KEYS: [&'static str; 5]
Every key a loader document is read for, in the order the contract states them — the reader below takes its keys from here, and the documentation’s examples are held to it. Every other key is ignored.
Sourcepub fn from_json(text: &str) -> Result<Self, TemplateError>
pub fn from_json(text: &str) -> Result<Self, TemplateError>
Read a loader document from its JSON text.
§Errors
TemplateError::MalformedLoader naming what is wrong: text that is not a JSON
object, a missing or empty reference, a missing or empty entry, a search_path
that is not a list of absolute directories, templates that are not {name, source}
string pairs, or a digest that is not a string.
Sourcepub fn new(
reference: impl Into<String>,
entry: impl Into<String>,
) -> Result<Self, TemplateError>
pub fn new( reference: impl Into<String>, entry: impl Into<String>, ) -> Result<Self, TemplateError>
A loader document naming entry, recorded as reference, over nothing yet.
§Errors
TemplateError::MalformedLoader for an empty reference or entry, as
LoaderDocument::from_json refuses one.
Sourcepub fn with_directory(
self,
directory: impl Into<PathBuf>,
) -> Result<Self, TemplateError>
pub fn with_directory( self, directory: impl Into<PathBuf>, ) -> Result<Self, TemplateError>
Add directory to the end of the search path.
§Errors
TemplateError::MalformedLoader for a directory that is not absolute, as
LoaderDocument::from_json refuses one: a relative one would resolve against
whatever directory the render happens to run in.
Sourcepub fn with_template(
self,
name: impl Into<String>,
source: impl Into<String>,
) -> Result<Self, TemplateError>
pub fn with_template( self, name: impl Into<String>, source: impl Into<String>, ) -> Result<Self, TemplateError>
Register a template’s source under name, searched after every directory.
§Errors
TemplateError::MalformedLoader for an empty name or source, as
LoaderDocument::from_json refuses one.
Sourcepub fn with_digest(self, digest: Sha256Digest) -> Self
pub fn with_digest(self, digest: Sha256Digest) -> Self
Expect the chain to compute digest.
Sourcepub fn reference(&self) -> &str
pub fn reference(&self) -> &str
What an item rendered from this document records as its provenance template.
Sourcepub fn load(&self) -> Result<Template, TemplateError>
pub fn load(&self) -> Result<Template, TemplateError>
Load the entry over the search path and the registered pairs, and hold its digest to the stated one.
§Errors
Every refusal of TemplateLoader::load_name — an unreadable or missing search path
directory among them, named — and TemplateError::LoaderDigest naming both digests
when a stated one is not the one the chain computes.