[−][src]Struct reinda_core::template::Template
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]
R: FnMut(Fragment, Appender<'_>) -> Result<(), E>,
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
Auto Trait Implementations
impl RefUnwindSafe for Template
[src]
impl Send for Template
[src]
impl Sync for Template
[src]
impl Unpin for Template
[src]
impl UnwindSafe for Template
[src]
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>,