pub struct Template { /* private fields */ }Expand description
A simple template engine for prompt templates.
Templates use {{VARIABLE}} syntax for placeholders and {{> partial}} for
including shared templates. Variables are replaced with the provided values.
Comments using {# comment #} syntax are stripped.
§Example
let partials = HashMap::from([("header", "Common Header\n")]);
let template = Template::new("{{> header}}\nReview this diff:\n{{DIFF}}");
let variables = HashMap::from([("DIFF", "+ new line")]);
let rendered = template.render_with_partials(&variables, &partials)?;Implementations§
§impl Template
impl Template
pub fn render(
&self,
variables: &HashMap<&str, String>,
) -> Result<String, TemplateError>
pub fn render( &self, variables: &HashMap<&str, String>, ) -> Result<String, TemplateError>
Render the template with the provided variables.
pub fn render_with_partials(
&self,
variables: &HashMap<&str, String>,
partials: &HashMap<String, String>,
) -> Result<String, TemplateError>
pub fn render_with_partials( &self, variables: &HashMap<&str, String>, partials: &HashMap<String, String>, ) -> Result<String, TemplateError>
Render the template with variables and partials support.
Partials are processed recursively, with the same variables passed to each partial. Circular references are detected and reported with a clear error.
pub fn render_with_log(
&self,
template_name: &str,
variables: &HashMap<&str, String>,
partials: &HashMap<String, String>,
) -> Result<RenderedTemplate, TemplateError>
pub fn render_with_log( &self, template_name: &str, variables: &HashMap<&str, String>, partials: &HashMap<String, String>, ) -> Result<RenderedTemplate, TemplateError>
Render the template with variables and partials, returning substitution log.
This is the primary method for reducer-integrated rendering. It returns both the rendered content and a detailed log of all substitutions, enabling validation based on what was actually substituted rather than regex scanning.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more