MiniTemplate

Struct MiniTemplate 

Source
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>

Source

pub fn new() -> Self

👎Deprecated

Creates a new instance. Use MiniTemplate::default instead.

Source

pub fn add_default_modifiers(&mut self)

Adds the following modifiers:

slice, regex, match, replace, replace_regex, upper, lower, repeat, add, sub, mul, div

Source

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.

Source

pub fn add_template( &mut self, key: K, tpl: String, ) -> Result<Option<Template>, ParseError>

Register a new Template for a give key

Source

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§

Source§

impl<K: Default + Eq + Hash> Default for MiniTemplate<K>

Source§

fn default() -> MiniTemplate<K>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.