Skip to main content

Template

Struct Template 

Source
pub struct Template { /* private fields */ }
Expand description

A loaded template: its chain, its declared set and its digest.

Implementations§

Source§

impl Template

Source

pub fn expand(&self, answers: &Answers) -> Result<Self, TemplateError>

This template with every template an expression names for answers added to its chain — each with the files its own literals name — and their front matter merged into the declared set under the same rules as the rest of the chain.

Which file an expression names can depend on the answers, so it is found by rendering: leniently, from the answers that fit their declarations and the defaults of the rest, every tag naming a template by an expression reporting what it named. A file found that way may declare a variable, or a nearer default, that decides what an expression names, so it repeats until a render names what the one before it did; a file only an earlier render named is not part of the chain. Each file so found joins the chain at the tag that names it, exactly as a file a literal names would: its nearness is its own distance from the rendered template. The expanded chain is in first-load order — the order that last render first read each file, then any it did not read. A template named by no expression expands to its own files in that order.

Template::unanswered, Template::resolve and Template::render each expand first, so a caller need not.

§Errors

TemplateError::Malformed, TemplateError::Unreadable and TemplateError::NotFound for a file found this way, or one its literals name, as for any chain file; TemplateError::ChainConflict for a declaration of it whose type or items another chain file’s contradicts; and TemplateError::Malformed for the rendered template when the files its expressions name give defaults that name one another in turn, so that what they name never settles.

Source

pub fn name(&self) -> &str

The rendered template’s resolved name.

Source

pub fn digest(&self) -> &str

The chain’s digest.

Source

pub fn variables(&self) -> &[TemplateVariable]

The declared set, in declaration order along the chain.

Source

pub fn chain(&self) -> impl Iterator<Item = &str>

The resolved name of every file of the chain, in first-load order: the files Template::digest is taken over, in its order. For a loaded template these are the rendered one and each extends, include and import its literals reach; what Template::expand answers adds each template an expression names.

Source

pub fn describe(&self) -> TemplateVariables

The declared set as template variables reports it.

Source

pub fn unanswered( &self, answers: &Answers, ) -> Result<Vec<TemplateVariable>, TemplateError>

The declared variables answers leaves unanswered, in declaration order — whether or not a default covers them — over the chain Template::expand reaches for answers. What a prompting caller asks for; answering one can name a further template, so a caller asks again until nothing new is left.

§Errors

TemplateError::UnknownAnswer and TemplateError::MistypedAnswer, as Template::render refuses them.

Source

pub fn resolve( &self, answers: &Answers, ) -> Result<BTreeMap<String, Value>, TemplateError>

Every declared variable’s value — over the chain Template::expand reaches for answers — its answer, else its default, else null for an optional one.

§Errors

TemplateError::UnknownAnswer naming every answer to no declared variable, TemplateError::MistypedAnswer for an answer not of its variable’s type, and TemplateError::MissingRequired naming every required variable left unanswered.

Source

pub fn render( &self, answers: &Answers, ) -> Result<RenderedTemplate, TemplateError>

Render the template from answers, over the chain Template::expand reaches for them: a template an expression names is part of the chain, its declarations part of the declared set the answers are held to, and its bytes part of the digest.

§Errors

Every refusal of Template::expand and Template::resolve, and TemplateError::Render for a render that fails — an undefined name among them.

Trait Implementations§

Source§

impl Clone for Template

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 Template

Source§

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

Formats the value using the given formatter. Read more

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.