[][src]Struct funcy::TemplateRenderer

pub struct TemplateRenderer<'a> { /* fields omitted */ }

Renders Funcy template strings.

Example

struct Echo();
impl funcy::PlaceholderFunction for Echo {
    fn placeholder_fn_handler<'a>(&mut self, _name: &'a str, arg: &'a str) -> Result<String, String> {
        Ok(arg.to_string())
    }
}

let mut tr = funcy::TemplateRenderer::with_template("<!$ echo Hello>, World!");
tr.set_placeholder_fn("echo", Box::new(Echo()));
assert_eq!(tr.render().unwrap(), "Hello, World!");

Implementations

impl<'a> TemplateRenderer<'a>[src]

pub fn new() -> Self[src]

Creates a TemplateRenderer with an empty template

pub fn with_template(inp_str: &'a str) -> Self[src]

Creates a TemplateRenderer with the specified template

pub fn set_template(&mut self, inp_str: &'a str)[src]

Sets the renderer's template string

pub fn set_placeholder_fn(
    &mut self,
    name: &'a str,
    thefn: Box<dyn PlaceholderFunction>
)
[src]

Adds/replaces the specified placeholder function

pub fn append_placeholders(
    &mut self,
    map: HashMap<&'a str, Box<dyn PlaceholderFunction>>
)
[src]

Appends placeholder functions from a HashMap to the current placeholder functions

pub fn set_placeholders(
    &mut self,
    map: HashMap<&'a str, Box<dyn PlaceholderFunction>>
)
[src]

Overwrites current placeholder functions with the HashMap

pub fn render(&mut self) -> Result<String, RenderError<'_>>[src]

Renders the template into a String

Trait Implementations

impl<'a> Debug for TemplateRenderer<'a>[src]

impl<'a> Default for TemplateRenderer<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for TemplateRenderer<'a>

impl<'a> !Send for TemplateRenderer<'a>

impl<'a> !Sync for TemplateRenderer<'a>

impl<'a> Unpin for TemplateRenderer<'a>

impl<'a> !UnwindSafe for TemplateRenderer<'a>

Blanket Implementations

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

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

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

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

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

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.

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.