[−][src]Struct funcy::TemplateRenderer
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]
&mut self,
name: &'a str,
thefn: Box<dyn PlaceholderFunction>
)
Adds/replaces the specified placeholder function
pub fn append_placeholders(
&mut self,
map: HashMap<&'a str, Box<dyn PlaceholderFunction>>
)
[src]
&mut self,
map: HashMap<&'a str, Box<dyn PlaceholderFunction>>
)
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]
&mut self,
map: HashMap<&'a str, Box<dyn PlaceholderFunction>>
)
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]
pub fn default() -> 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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,