Function string_template_plus::parse_template
source · pub fn parse_template(templ_str: &str) -> Result<Template, Error>
Expand description
Parses the template from string and makes a Template
. Which you can render later./// Main Template that get’s passed around, consists of [Vec
] of TemplatePart
let templ = parse_template("hello {nickname?name?}. You're $(printf \"%.1f\" {weight})kg").unwrap();
let parts = concat!("[Lit(\"hello \"), ",
"Any([Var(\"nickname\", \"\"), Var(\"name\", \"\"), Lit(\"\")]), ",
"Lit(\". You're \"), ",
"Cmd([Lit(\"printf \\\"%.1f\\\" \"), Var(\"weight\", \"\")]), ",
"Lit(\"kg\")]");
assert_eq!(parts, format!("{:?}", templ));
}