pub struct CompiledTemplate { /* private fields */ }Expand description
A template body compiled into a flat list of Segments.
Created once at parse time via CompiledTemplate::compile; rendered
on every request via CompiledTemplate::render without revisiting the
original Value tree.
Implementations§
Source§impl CompiledTemplate
impl CompiledTemplate
Sourcepub fn compile(body: &Value) -> Result<Self, TemplateError>
pub fn compile(body: &Value) -> Result<Self, TemplateError>
Walks the Value tree depth-first and compiles it into a flat list of
Segments. Done once at parse time so render time only iterates
the segment list.
Sourcepub fn render(
&self,
ctx: &GeneratorContext,
rng: &mut impl Rng,
) -> Result<String, TemplateError>
pub fn render( &self, ctx: &GeneratorContext, rng: &mut impl Rng, ) -> Result<String, TemplateError>
Iterates the compiled segments and writes static bytes and resolved
placeholder values into a String buffer.
For each placeholder:
- If the name is present in
ctx.resolved(pre-serialized:globalorENV:value), it is written verbatim. - Otherwise, a fresh value is generated via
ctx.generate_by_nameand serialized inline.
Auto Trait Implementations§
impl Freeze for CompiledTemplate
impl RefUnwindSafe for CompiledTemplate
impl Send for CompiledTemplate
impl Sync for CompiledTemplate
impl Unpin for CompiledTemplate
impl UnsafeUnpin for CompiledTemplate
impl UnwindSafe for CompiledTemplate
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