Skip to main content

Answers

Struct Answers 

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

The answers a template is rendered from, by variable name.

Parsed from an answers document (Answers::from_yaml) or built in code. Nothing here knows a template’s variables: an answer naming no declared variable, or of the wrong type, is refused when the answers meet the template, by super::Template::render.

Implementations§

Source§

impl Answers

Source

pub fn new() -> Self

Answers to nothing: rendered from these, every default is taken and every required variable is refused.

Source

pub fn from_yaml(text: &str) -> Result<Self, TemplateError>

Read an answers document: a top-level YAML mapping from variable name to value.

An empty document is no answers.

§Errors

TemplateError::MalformedAnswers for a document that is not YAML, or whose top level is not a mapping with string keys.

Source

pub fn set(&mut self, name: impl Into<String>, value: Value) -> &mut Self

Answer name with value.

Source

pub fn set_text( &mut self, name: impl Into<String>, text: impl Into<String>, ) -> &mut Self

Answer name with text as a command line gives it: taken literally for a string or text variable, and read as YAML for any other type.

Source

pub fn unset(&mut self, name: impl Into<String>) -> &mut Self

Leave name unanswered — and, over earlier answers, take away the one they gave.

Source

pub fn overlay(&self, later: &Self) -> Self

These answers with later laid over them: a name later answers takes its answer, a name later unsets is unanswered, and every other name keeps what it had.

Source

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

Every name answered, in name order — an unset name is not answered.

Trait Implementations§

Source§

impl Clone for Answers

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 Answers

Source§

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

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

impl Default for Answers

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Answers

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 Answers

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.