pub struct MiniTemplate<K: Eq + Hash> { /* private fields */ }Expand description
A Storage for Templates
A MiniTemplate instance is used to parse, save and render templates.
Implementations§
Source§impl<K: Eq + Hash> MiniTemplate<K>
impl<K: Eq + Hash> MiniTemplate<K>
Sourcepub fn new() -> Self
👎Deprecated
pub fn new() -> Self
Creates a new instance.
Use MiniTemplate::default instead.
Sourcepub fn add_default_modifiers(&mut self)
pub fn add_default_modifiers(&mut self)
Adds the following modifiers:
slice, regex, match, replace, replace_regex, upper, lower, repeat, add, sub, mul, div
Sourcepub fn add_modifier(&mut self, key: &'static str, modifier: &'static Modifier)
pub fn add_modifier(&mut self, key: &'static str, modifier: &'static Modifier)
Register a new modifier
You can implement modifiers by hand. But that will result quite complex setup code.
Preferably you should take a look at the [mini_template::modifier::create_modifier] macro.
Sourcepub fn add_template(
&mut self,
key: K,
tpl: String,
) -> Result<Option<Template>, ParseError>
pub fn add_template( &mut self, key: K, tpl: String, ) -> Result<Option<Template>, ParseError>
Register a new Template for a give key
Sourcepub fn render<VC: VariableContainer>(
&self,
key: &K,
data: VC,
) -> Result<String, Error<'_>>
pub fn render<VC: VariableContainer>( &self, key: &K, data: VC, ) -> Result<String, Error<'_>>
Render the template for a given key.
§Error
This function will return the following errors:
- Modifier: An unhandled error occurred inside a modifier
- UnknownTemplate: There is no template with the given key registered
- UnknownModifier: The template contains a unknown modifier
- UnknownVariable: The template contains a unknown variable
Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for MiniTemplate<K>
impl<K> !RefUnwindSafe for MiniTemplate<K>
impl<K> !Send for MiniTemplate<K>
impl<K> !Sync for MiniTemplate<K>
impl<K> Unpin for MiniTemplate<K>where
K: Unpin,
impl<K> !UnwindSafe for MiniTemplate<K>
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