Struct new_string_template::template::Template [−][src]
pub struct Template { /* fields omitted */ }
Expand description
Struct to store the template
Implementations
impl Template
[src]
impl Template
[src]pub fn new<T: Into<String>>(template: T) -> Self
[src]
pub fn new<T: Into<String>>(template: T) -> Self
[src]Create a new Template Instance with the default regex
Example
let input_template = "Some {{ Template }}"; let template_instance = Template::new(input_template);
pub fn with_regex(self, regex: &Regex) -> Self
[src]
pub fn with_regex(self, regex: &Regex) -> Self
[src]Change used regex to an custom one The regex needs to include one valid capture group
Example
let templ = Template::new(template_string).with_regex(&custom_regex);
pub fn render(
&self,
values: &HashMap<&str, &str>
) -> Result<String, TemplateError>
[src]
pub fn render(
&self,
values: &HashMap<&str, &str>
) -> Result<String, TemplateError>
[src]Render the template with the provided values
Errors
This function Errors on the first problem encountered
Example
let templ_str = "Something {data1} be {data2}, and { not here }"; let templ = Template::new(templ_str); let data = { let mut map = HashMap::new(); map.insert("data1", "should"); map.insert("data2", "here"); map }; let rendered = templ.render(&data).expect("Expected Result to be Ok"); assert_eq!("Something should be here, and { not here }", rendered);
pub fn render_nofail(&self, values: &HashMap<&str, &str>) -> String
[src]
pub fn render_nofail(&self, values: &HashMap<&str, &str>) -> String
[src]Render the template with the provided values Returns Full Converted String and no Result
Example
let templ_str = "Something {data1} be {data2}, and { not here }"; let templ = Template::new(templ_str); let data = { let mut map = HashMap::new(); map.insert("data1", "should"); // map.insert("data2", "here"); map }; let rendered = templ.render_nofail(&data); assert_eq!("Something should be {data2}, and { not here }", rendered);