pub struct Template(/* private fields */);Expand description
Template holds the prepared result of parsing a template. Because the template does not need to be reparsed, subsequent executions come at a low cost.
Implementations§
Source§impl Template
impl Template
Sourcepub fn render(&self, ctx: &impl Context) -> Result<String>
pub fn render(&self, ctx: &impl Context) -> Result<String>
Render a template as a string.
§Usage
let t = Templar::global().parse_expression("5 + 5")?;
assert_eq!(t.render(&context)?, "10");Sourcepub fn exec(&self, ctx: &impl Context) -> Data
pub fn exec(&self, ctx: &impl Context) -> Data
Execute a template, getting a InnerData from the unstructured crate as a result.
many of the native rust types implement into() on InnerData making direct comparisons
easy.
§Usage
let t = Templar::global().parse_expression("5 + 5")?;
assert_eq!(*t.exec(&context), 10i64);Trait Implementations§
Source§impl From<Template> for TemplateTree
impl From<Template> for TemplateTree
Source§fn from(t: Template) -> TemplateTree
fn from(t: Template) -> TemplateTree
Converts to this type from the input type.
Source§impl TryFrom<Option<TemplateTree>> for Template
impl TryFrom<Option<TemplateTree>> for Template
Source§type Error = TemplarError
type Error = TemplarError
The type returned in the event of a conversion error.
Source§impl TryFrom<TemplateTree> for Template
impl TryFrom<TemplateTree> for Template
Source§type Error = TemplarError
type Error = TemplarError
The type returned in the event of a conversion error.
Source§fn try_from(value: TemplateTree) -> Result<Self>
fn try_from(value: TemplateTree) -> Result<Self>
Performs the conversion.
Auto Trait Implementations§
impl Freeze for Template
impl !RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more