Struct hcl::template::IfDirective
source · pub struct IfDirective {
pub cond_expr: Expression,
pub true_template: Template,
pub false_template: Option<Template>,
pub if_strip: Strip,
pub else_strip: Strip,
pub endif_strip: Strip,
}Expand description
The template if directive is the template equivalent of the conditional expression, allowing
selection of one of two sub-templates based on the condition result.
Fields§
§cond_expr: ExpressionThe condition expression.
true_template: TemplateThe template that is included in the result string if the conditional expression evaluates
to true.
false_template: Option<Template>The template that is included in the result string if the if branch’s conditional
expression evaluates to false. This is None if there is no else branch in which case
the result string will be empty.
if_strip: StripThe whitespace strip mode to use on the template elements preceeding and following after
the if expression.
else_strip: StripThe whitespace strip mode to use on the template elements preceeding and following after
the else expression. This has no effect if false_template is None.
endif_strip: StripThe whitespace strip mode to use on the template elements preceeding and following after
the endif marker of this directive.
Implementations§
source§impl IfDirective
impl IfDirective
sourcepub fn new<T>(cond_expr: T, true_template: Template) -> IfDirectivewhere
T: Into<Expression>,
pub fn new<T>(cond_expr: T, true_template: Template) -> IfDirectivewhere T: Into<Expression>,
Creates a new IfDirective from a conditional expression and a template that is included
in the result string if the conditional expression evaluates to true.
sourcepub fn with_false_template<T>(self, else_template: T) -> IfDirectivewhere
T: Into<Template>,
pub fn with_false_template<T>(self, else_template: T) -> IfDirectivewhere T: Into<Template>,
Adds a template for the else branch which is included in the result string if the
condition of the IfDirective evaluates to false and returns the modified IfDirective.
sourcepub fn with_if_strip(self, strip: Strip) -> IfDirective
pub fn with_if_strip(self, strip: Strip) -> IfDirective
Sets the whitespace strip mode to use on the template elements preceeding and following
after the if expression and returns the modified IfDirective.
sourcepub fn with_else_strip(self, strip: Strip) -> IfDirective
pub fn with_else_strip(self, strip: Strip) -> IfDirective
Sets the whitespace strip mode to use on the template elements preceeding and following
after the else expression and returns the modified IfDirective.
sourcepub fn with_endif_strip(self, strip: Strip) -> IfDirective
pub fn with_endif_strip(self, strip: Strip) -> IfDirective
Sets the whitespace strip mode to use on the template elements preceeding and following
after the endif marker of this directive and returns the modified IfDirective.
Trait Implementations§
source§impl Clone for IfDirective
impl Clone for IfDirective
source§fn clone(&self) -> IfDirective
fn clone(&self) -> IfDirective
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for IfDirective
impl Debug for IfDirective
source§impl Format for IfDirective
impl Format for IfDirective
source§fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where W: Write,
source§impl From<IfDirective> for Directive
impl From<IfDirective> for Directive
source§fn from(directive: IfDirective) -> Self
fn from(directive: IfDirective) -> Self
source§impl PartialEq<IfDirective> for IfDirective
impl PartialEq<IfDirective> for IfDirective
source§fn eq(&self, other: &IfDirective) -> bool
fn eq(&self, other: &IfDirective) -> bool
self and other values to be equal, and is used
by ==.impl Eq for IfDirective
impl StructuralEq for IfDirective
impl StructuralPartialEq for IfDirective
Auto Trait Implementations§
impl RefUnwindSafe for IfDirective
impl Send for IfDirective
impl Sync for IfDirective
impl Unpin for IfDirective
impl UnwindSafe for IfDirective
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.