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): boolfetch(string $template, array $data = []): void(PHP 用 echo,Rust 返回 String)display(string $content, array $data = []): void(PHP 用 echo,Rust 返回 String)config(array $config): voidgetConfig(string $name): mixed
Required Methods§
Sourcefn fetch(
&self,
template: &str,
data: &HashMap<String, Value>,
) -> Result<String, ViewError>
fn fetch( &self, template: &str, data: &HashMap<String, Value>, ) -> Result<String, ViewError>
渲染模板文件(对齐 PHP fetch)
Sourcefn display(
&self,
content: &str,
data: &HashMap<String, Value>,
) -> Result<String, ViewError>
fn display( &self, content: &str, data: &HashMap<String, Value>, ) -> Result<String, ViewError>
渲染字符串内容(对齐 PHP display)
Sourcefn set_config(&mut self, config: ViewConfig)
fn set_config(&mut self, config: ViewConfig)
设置配置(对齐 PHP config)
Sourcefn get_config(&self, name: &str) -> Option<Value>
fn get_config(&self, name: &str) -> Option<Value>
读取配置(对齐 PHP getConfig)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".