Skip to main content

TemplateBuffer

Struct TemplateBuffer 

Source
pub struct TemplateBuffer<'a> { /* private fields */ }
Expand description

A template buffer. This is the type that gets passed to closures inside templates.

Example:

    html! {
        |tmpl /*: &mut TemplateBuffer */| tmpl << "Some String";
    };

Implementations§

Source§

impl<'a> TemplateBuffer<'a>

Source

pub fn record_error<E: Into<Box<dyn Error + Send + Sync>>>(&mut self, e: E)

Record an error. If a template calls this function, rendering will be short-circuited and the error will be returned to the user.

FEATURE:

  • With “alloc” but without “std”, accepts anything that can be converted to a string (anything implementing ToString).
  • Without “std” or “alloc”, accepts a static &str. Multiple calls will record the first error.
Source

pub fn write_raw(&mut self, text: &str)

Write a raw string to the template output.

Source

pub fn write_fmt(&mut self, args: Arguments<'_>)

Escape and write the formatted arguments to the template output.

Example:

write!(tmpl, "{} + {}", 0, 1);
Source

pub fn write_str(&mut self, text: &str)

Escape and write a string to the template output.

Source

pub fn as_writer<'b>(&'b mut self) -> TemplateWriter<'a, 'b>

Returns an escaping Write adapter.

Source

pub fn as_raw_writer<'b>(&'b mut self) -> RawTemplateWriter<'a, 'b>

Returns a non-escaping Write adapter.

Trait Implementations§

Source§

impl<'a, 'b, T> Shl<T> for &'a mut TemplateBuffer<'b>
where T: RenderOnce,

Source§

fn shl(self, component: T)

Render the component into the template.

Note: If writing to the template fails, this method will neither panic nor return errors. Instead, no more data will be written to the template and horrorshow abort template rendering (return an error) when it re-gains control.

Source§

type Output = ()

The resulting type after applying the << operator.

Auto Trait Implementations§

§

impl<'a> Freeze for TemplateBuffer<'a>

§

impl<'a> !RefUnwindSafe for TemplateBuffer<'a>

§

impl<'a> !Send for TemplateBuffer<'a>

§

impl<'a> !Sync for TemplateBuffer<'a>

§

impl<'a> Unpin for TemplateBuffer<'a>

§

impl<'a> !UnwindSafe for TemplateBuffer<'a>

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.