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: Expression
The condition expression.
true_template: Template
The 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: Strip
The whitespace strip mode to use on the template elements preceeding and following after
the if
expression.
else_strip: Strip
The 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: Strip
The 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) -> IfDirective
pub fn with_false_template<T>(self, else_template: T) -> IfDirective
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 From<IfDirective> for IfDirective
impl From<IfDirective> for IfDirective
Source§fn from(value: IfDirective) -> Self
fn from(value: IfDirective) -> Self
Source§impl From<IfDirective> for IfDirective
impl From<IfDirective> for IfDirective
Source§fn from(value: IfDirective) -> Self
fn from(value: IfDirective) -> Self
Source§impl PartialEq for IfDirective
impl PartialEq for IfDirective
impl Eq for IfDirective
impl StructuralPartialEq for IfDirective
Auto Trait Implementations§
impl Freeze for IfDirective
impl RefUnwindSafe for IfDirective
impl Send for IfDirective
impl Sync for IfDirective
impl Unpin for IfDirective
impl UnwindSafe for IfDirective
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.