Struct string_template_plus::Template 
source · pub struct Template { /* private fields */ }Expand description
Main Template that get’s passed around, consists of [Vec] of TemplatePart
    let templ = Template::parse_template("hello {nickname?name}. You're $(printf \"%.1f\" {weight})kg").unwrap();
    let mut vars: HashMap<String, String> = HashMap::new();
    vars.insert("name".into(), "John".into());
    vars.insert("weight".into(), "132.3423".into());
    let rendered = templ
        .render(&RenderOptions {
            wd: PathBuf::from("."),
            variables: vars,
            shell_commands: true,
        })
        .unwrap();
    assert_eq!(rendered, "hello John. You're 132.3kg");
}Implementations§
source§impl Template
 
impl Template
sourcepub fn parse_template(templ_str: &str) -> Result<Template, Error>
 
pub fn parse_template(templ_str: &str) -> Result<Template, Error>
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 = Template::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 \"), Lit(\"\\\"\"), Lit(\"%.1f\"), Lit(\"\\\"\"), Lit(\" \"), Var(\"weight\", \"\")]), ",
                 "Lit(\"kg\")]");
    assert_eq!(parts, format!("{:?}", templ.parts()));
}pub fn parts(&self) -> &Vec<TemplatePart>
pub fn original(&self) -> &str
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
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
Mutably borrows from an owned value. Read more