[][src]Struct reinda_core::template::Template

pub struct Template { /* fields omitted */ }

A parsed template.

Template syntax

Our template syntax is super simple and is really just a glorified search-and-replace. The input is checked for "fragments" which have the syntax {{: foo :}}. The start token is actually {{: (note the whitespace!). So {{:foo:}} is not recognized as fragment.

There are two additional constraints: the fragment must not contain a newline and must be shorter than MAX_FRAGMENT_LEN. If these conditions are not met, the fragment start token is ignored.

The string between the start and end tag is then trimmed (excess whitespace removed) and parsed into a Fragment. See that type's documentation for information about the existing kinds of fragments.

Implementations

impl Template[src]

pub fn parse(input: Bytes) -> Result<Self, Error>[src]

Parses the input byte string as template. Returns Err on parse error.

pub fn into_already_rendered(self) -> Result<Bytes, Self>[src]

Returns Some(out) if this template does not have any fragments at all. out is equal to the input that was passed to parse.

pub fn fragments(&self) -> impl Iterator<Item = &Fragment>[src]

Returns an iterator over all fragments.

pub fn raw_input(&self) -> &Bytes[src]

Returns the raw input that was passed to parse.

pub fn render<R, E>(self, mut replacer: R) -> Result<Bytes, E> where
    R: FnMut(Fragment, Appender<'_>) -> Result<(), E>, 
[src]

Renders the template using replacer to evaluate the fragments.

Replacing/evaluating fragments

For each fragment in the input template, the replacer is called with the parsed fragment. For example, the template string foo {{: bar :}} baz {{: config.data :}}x would lead to two calls to replacer, with the following strings as first parameter:

  • bar
  • config.data

As you can see, excess whitespace is stripped before passing the string within the fragment.

Trait Implementations

impl Debug for Template[src]

Auto Trait Implementations

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.