pub struct TeraEngine { /* private fields */ }tera only.Expand description
A Tera template engine instance.
Implementations§
Source§impl TeraEngine
impl TeraEngine
Sourcepub fn from_glob(pattern: &str) -> Result<Self, String>
pub fn from_glob(pattern: &str) -> Result<Self, String>
Load all templates matching glob_pattern, e.g. "templates/**/*".
The pattern is passed directly to tera::Tera::new.
Sourcepub fn from_dir(dir: &str) -> Result<Self, String>
pub fn from_dir(dir: &str) -> Result<Self, String>
Load all templates from dir. Equivalent to from_glob("dir/**/*").
Sourcepub fn from_raw(templates: &[(&str, &str)]) -> Result<Self, String>
pub fn from_raw(templates: &[(&str, &str)]) -> Result<Self, String>
Build an engine from in-memory template strings — useful for testing.
templates is a slice of (name, content) pairs. Has no glob, so
reload always returns Err for an engine built this way.
Sourcepub fn render(
&self,
template_name: &str,
ctx: &Context,
) -> Result<String, String>
pub fn render( &self, template_name: &str, ctx: &Context, ) -> Result<String, String>
Render template_name with ctx and return the output as a String.
Sourcepub fn response(
&self,
template_name: &str,
ctx: &Context,
) -> Result<Response, String>
pub fn response( &self, template_name: &str, ctx: &Context, ) -> Result<Response, String>
Render template_name and wrap the output in a 200 OK HTML Response.
Sourcepub fn reload(&mut self) -> Result<(), String>
pub fn reload(&mut self) -> Result<(), String>
Re-read every template from the glob this engine was created with, replacing all currently-loaded templates.
Picks up edited content in existing files and newly added or removed files matching the original glob — it’s a full re-glob, not a diff.
Builds the replacement set of templates in full before swapping it in,
rather than mutating the live template set in place (which is what
tera::Tera::full_reload does, and why this doesn’t just call it) —
so a syntax error in one edited file fails the whole reload atomically
and this engine keeps serving its last-known-good templates, instead
of serving a half-reloaded, partially-broken set. Returns Err if:
- this engine was built with
TeraEngine::from_raw(no glob to re-read), or - any template now fails to parse (e.g. a syntax error mid-edit) or
an
{% extends %}/{% import %}chain no longer resolves.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TeraEngine
impl !UnwindSafe for TeraEngine
impl Freeze for TeraEngine
impl Send for TeraEngine
impl Sync for TeraEngine
impl Unpin for TeraEngine
impl UnsafeUnpin for TeraEngine
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.