Skip to main content

TemplateRenderer

Trait TemplateRenderer 

Source
pub trait TemplateRenderer: Send + Sync {
    // Required methods
    fn render(
        &self,
        template_name: &str,
        context: &Value,
    ) -> TemplateResult<String>;
    fn register_template(
        &mut self,
        name: &str,
        content: &str,
    ) -> TemplateResult<()>;
    fn register_template_file(
        &mut self,
        name: &str,
        path: &Path,
    ) -> TemplateResult<()>;
    fn register_templates_from_dir(
        &mut self,
        dir: &Path,
        extension: Option<&str>,
    ) -> TemplateResult<()>;

    // Provided method
    fn render_async<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        template_name: &'life1 str,
        context: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = TemplateResult<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

模板渲染器 trait

Required Methods§

Source

fn render(&self, template_name: &str, context: &Value) -> TemplateResult<String>

渲染单个模板

Source

fn register_template(&mut self, name: &str, content: &str) -> TemplateResult<()>

注册模板

Source

fn register_template_file( &mut self, name: &str, path: &Path, ) -> TemplateResult<()>

注册模板文件

Source

fn register_templates_from_dir( &mut self, dir: &Path, extension: Option<&str>, ) -> TemplateResult<()>

从目录注册所有模板

Provided Methods§

Source

fn render_async<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, template_name: &'life1 str, context: &'life2 Value, ) -> Pin<Box<dyn Future<Output = TemplateResult<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

异步渲染单个模板

Implementors§