Struct new_string_template::template::Template[][src]

pub struct Template { /* fields omitted */ }
Expand description

Struct to store the template

Implementations

impl Template[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]

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]

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]

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);

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.