pub struct EmailRenderer { /* private fields */ }Expand description
Holds a Tera engine plus per-instance rendering helpers.
Cheap to clone (the inner Tera is wrapped in Arc internally
when shared across handlers — pass Arc<EmailRenderer> if you
want to avoid the Tera clone cost).
Implementations§
Source§impl EmailRenderer
impl EmailRenderer
Sourcepub fn from_dir(dir: impl AsRef<Path>) -> Result<Self, EmailRenderError>
pub fn from_dir(dir: impl AsRef<Path>) -> Result<Self, EmailRenderError>
Load every *.txt, *.html, *.subject.txt under dir.
Subdirectories are walked.
§Errors
Returns the underlying Tera error when a template doesn’t parse, or the directory glob can’t be evaluated.
Sourcepub fn from_pairs(pairs: Vec<(&str, &str)>) -> Result<Self, EmailRenderError>
pub fn from_pairs(pairs: Vec<(&str, &str)>) -> Result<Self, EmailRenderError>
Build from in-memory (name, source) pairs. Useful for
tests and one-off scripts that don’t want a templates dir.
§Errors
Returns the underlying Tera error if a template doesn’t parse.
Sourcepub fn tera(&self) -> &Tera
pub fn tera(&self) -> &Tera
Borrow the inner Tera. Useful when you want to register custom filters / functions.
Sourcepub fn tera_mut(&mut self) -> &mut Tera
pub fn tera_mut(&mut self) -> &mut Tera
Mutable borrow for filter/function registration at startup.
Sourcepub fn render(
&self,
name: &str,
context: &Context,
) -> Result<Email, EmailRenderError>
pub fn render( &self, name: &str, context: &Context, ) -> Result<Email, EmailRenderError>
Render {name}.subject.txt, {name}.txt, and (optionally)
{name}.html and pack them into an Email. The returned
email has only subject, body, and html_body populated —
chain .to() / .from() / etc. before sending.
§Errors
Missing(name) when subject or text body is absent;
Tera(_) for any template error.
Auto Trait Implementations§
impl Freeze for EmailRenderer
impl !RefUnwindSafe for EmailRenderer
impl Send for EmailRenderer
impl Sync for EmailRenderer
impl Unpin for EmailRenderer
impl UnsafeUnpin for EmailRenderer
impl !UnwindSafe for EmailRenderer
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> 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 more