pub enum TemplatePart {
Lit(String),
Var(String, String),
Time(String),
Lisp(String, String, Vec<(usize, usize)>),
Cmd(Vec<TemplatePart>),
Any(Vec<TemplatePart>),
}
Expand description
Parts that make up a Template
. You can have literal strings, variables, time date format, command, or optional format with OPTIONAL_RENDER_CHAR
.
TemplatePart::Lit
= Literal Strings like "hi "
in "hi {name}"
TemplatePart::Var
= Variable part like "name"
in "hi {name}"
and format specifier
TemplatePart::Time
= Date time format like "%F"
in "Today: {%F}"
TemplatePart::Cmd
= Command like "echo world"
in "hello $(echo world)"
TemplatePart::Any
= Optional format like "name?age"
in "hello {name?age}"
TemplatePart::Cmd
and TemplatePart::Any
can in turn contain other TemplatePart
inside them. Haven’t tested on nesting complex ones within each other though.
Variants§
Lit(String)
Literal string, keep them as they are
Var(String, String)
Variable and format, uses the variable’s value in the rendered String
Time(String)
DateTime format, use chrono::Local
in the given format
Lisp(String, String, Vec<(usize, usize)>)
Lisp expression to calculate with the transformer
Cmd(Vec<TemplatePart>)
Shell Command, use the output of command in the rendered String
Any(Vec<TemplatePart>)
Multiple variables or TemplatePart
s, use the first one that succeeds
Implementations§
Source§impl TemplatePart
impl TemplatePart
pub fn lit(part: &str) -> Self
pub fn var(part: &str) -> Self
pub fn lisp(part: &str) -> Self
pub fn time(part: &str) -> Self
Sourcepub fn maybe_var(part: &str) -> Self
pub fn maybe_var(part: &str) -> Self
Parse a &str
into TemplatePart::Lit
, TemplatePart::Time
, or TemplatePart::Var
pub fn cmd(parts: Vec<TemplatePart>) -> Self
pub fn parse_cmd(part: &str) -> Result<Self, RenderTemplateError>
pub fn any(parts: Vec<TemplatePart>) -> Self
pub fn maybe_any(part: &str) -> Self
pub fn tokenize(templ: &str) -> Result<Vec<Self>, RenderTemplateError>
pub fn variables(&self) -> Vec<&str>
Trait Implementations§
Source§impl Clone for TemplatePart
impl Clone for TemplatePart
Source§fn clone(&self) -> TemplatePart
fn clone(&self) -> TemplatePart
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more