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
impl Answers
Sourcepub fn new() -> Self
pub fn new() -> Self
Answers to nothing: rendered from these, every default is taken and every required variable is refused.
Sourcepub fn from_yaml(text: &str) -> Result<Self, TemplateError>
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.
Sourcepub fn set(&mut self, name: impl Into<String>, value: Value) -> &mut Self
pub fn set(&mut self, name: impl Into<String>, value: Value) -> &mut Self
Answer name with value.
Sourcepub fn set_text(
&mut self,
name: impl Into<String>,
text: impl Into<String>,
) -> &mut Self
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.
Sourcepub fn unset(&mut self, name: impl Into<String>) -> &mut Self
pub fn unset(&mut self, name: impl Into<String>) -> &mut Self
Leave name unanswered — and, over earlier answers, take away the one they gave.