Skip to main content

LoaderDocument

Struct LoaderDocument 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_digest(self, digest: Sha256Digest) -> Self

Expect the chain to compute digest.

Source

pub fn reference(&self) -> &str

What an item rendered from this document records as its provenance template.

Source

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.

Trait Implementations§

Source§

impl Clone for LoaderDocument

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LoaderDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for LoaderDocument

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LoaderDocument

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.