pub struct SimpleEngine { /* private fields */ }Expand description
A lightweight template engine using format-string style substitution.
This engine provides simple {variable} substitution without the overhead
of a full template engine. It’s ideal for:
- Simple output templates
- Configuration messages
- Status displays
- Any template that just needs variable substitution
§Thread Safety
SimpleEngine is Send + Sync and can be shared across threads.
§Example
use standout_render::template::{SimpleEngine, TemplateEngine};
use serde_json::json;
let engine = SimpleEngine::new();
let data = json!({"status": "ok", "count": 42});
let output = engine.render_template(
"Status: {status}, Count: {count}",
&data,
).unwrap();
assert_eq!(output, "Status: ok, Count: 42");Implementations§
Source§impl SimpleEngine
impl SimpleEngine
Trait Implementations§
Source§impl Default for SimpleEngine
impl Default for SimpleEngine
Source§impl TemplateEngine for SimpleEngine
impl TemplateEngine for SimpleEngine
Source§fn render_template(
&self,
template: &str,
data: &Value,
) -> Result<String, RenderError>
fn render_template( &self, template: &str, data: &Value, ) -> Result<String, RenderError>
Renders a template string with the given data. Read more
Source§fn add_template(&mut self, name: &str, source: &str) -> Result<(), RenderError>
fn add_template(&mut self, name: &str, source: &str) -> Result<(), RenderError>
Adds a named template to the engine. Read more
Source§fn render_named(&self, name: &str, data: &Value) -> Result<String, RenderError>
fn render_named(&self, name: &str, data: &Value) -> Result<String, RenderError>
Renders a previously registered template. Read more
Source§fn has_template(&self, name: &str) -> bool
fn has_template(&self, name: &str) -> bool
Checks if a template with the given name exists.
Source§fn render_with_context(
&self,
template: &str,
data: &Value,
context: HashMap<String, Value>,
) -> Result<String, RenderError>
fn render_with_context( &self, template: &str, data: &Value, context: HashMap<String, Value>, ) -> Result<String, RenderError>
Renders a template with additional context values merged in. Read more
Source§fn supports_includes(&self) -> bool
fn supports_includes(&self) -> bool
Whether this engine supports template includes (
{% include %}).Source§fn supports_filters(&self) -> bool
fn supports_filters(&self) -> bool
Whether this engine supports filters (
{{ value | filter }}).Source§fn supports_control_flow(&self) -> bool
fn supports_control_flow(&self) -> bool
Whether this engine supports control flow (
{% for %}, {% if %}).Auto Trait Implementations§
impl Freeze for SimpleEngine
impl RefUnwindSafe for SimpleEngine
impl Send for SimpleEngine
impl Sync for SimpleEngine
impl Unpin for SimpleEngine
impl UnsafeUnpin for SimpleEngine
impl UnwindSafe for SimpleEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more