TemplateRenderer

Struct TemplateRenderer 

Source
pub struct TemplateRenderer<'a, T: Serialize> { /* private fields */ }
Expand description

Go Template Renderer

Implementations§

Source§

impl<'a, T: Serialize> TemplateRenderer<'a, T>

Source

pub fn new(template_content: &'a str, data: &'a T) -> Self

Creates a new template renderer.

§Arguments
  • template_content - Go template content as a string slice.
  • data - Data to be injected into the template, must implement Serialize.
Source

pub fn escape_html(self, escape: bool) -> Self

Sets whether to escape HTML in the output.

Defaults to false.

Source

pub fn use_missing_key_zero(self, use_zero: bool) -> Self

Sets whether to treat missing keys as zero values.

Go Template’s missingkey=zero option.

Source

pub fn render(self) -> Result<String, RenderError>

Executes the template rendering.

§Returns

Ok(String) if rendering was successful, Err(RenderError) otherwise.

Source§

impl<'a, T: Serialize> TemplateRenderer<'a, T>

Source

pub fn render_quick( template: &'a str, data: &'a T, ) -> Result<String, RenderError>

快速渲染模板的便捷方法

Source

pub fn render_html( template: &'a str, data: &'a T, ) -> Result<String, RenderError>

渲染HTML转义的模板

Auto Trait Implementations§

§

impl<'a, T> Freeze for TemplateRenderer<'a, T>

§

impl<'a, T> RefUnwindSafe for TemplateRenderer<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for TemplateRenderer<'a, T>
where T: Sync,

§

impl<'a, T> Sync for TemplateRenderer<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for TemplateRenderer<'a, T>

§

impl<'a, T> UnwindSafe for TemplateRenderer<'a, T>
where T: RefUnwindSafe,

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.