Skip to main content

TemplateEngine

Trait TemplateEngine 

Source
pub trait TemplateEngine: Send + Sync {
    // Required methods
    fn exists(&self, template: &str) -> bool;
    fn fetch(
        &self,
        template: &str,
        data: &HashMap<String, Value>,
    ) -> Result<String, ViewError>;
    fn display(
        &self,
        content: &str,
        data: &HashMap<String, Value>,
    ) -> Result<String, ViewError>;
    fn set_config(&mut self, config: ViewConfig);
    fn get_config(&self, name: &str) -> Option<Value>;
    fn as_any(&self) -> &(dyn Any + 'static);
}
Expand description

模板引擎接口(对齐 PHP think\contract\TemplateHandlerInterface

PHP 接口方法:

  • exists(string $template): bool
  • fetch(string $template, array $data = []): void(PHP 用 echo,Rust 返回 String)
  • display(string $content, array $data = []): void(PHP 用 echo,Rust 返回 String)
  • config(array $config): void
  • getConfig(string $name): mixed

Required Methods§

Source

fn exists(&self, template: &str) -> bool

模板是否存在(对齐 PHP exists

Source

fn fetch( &self, template: &str, data: &HashMap<String, Value>, ) -> Result<String, ViewError>

渲染模板文件(对齐 PHP fetch

Source

fn display( &self, content: &str, data: &HashMap<String, Value>, ) -> Result<String, ViewError>

渲染字符串内容(对齐 PHP display

Source

fn set_config(&mut self, config: ViewConfig)

设置配置(对齐 PHP config

Source

fn get_config(&self, name: &str) -> Option<Value>

读取配置(对齐 PHP getConfig

Source

fn as_any(&self) -> &(dyn Any + 'static)

返回 &dyn Any 以支持 downcast(Rust 特有,无 PHP 对应)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§