pub struct CompiledTemplates { /* private fields */ }Expand description
CompiledTemplates is useful when you have a set of templates
that you will expand frequently in a tight loop.
Because the underlying crate returns only references to Templates,
it is a covariant, self-referential structure that needs to be
constructed like this:
fn get_templates<'b>(
engine: &'b TemplateEngine
) -> anyhow::Result<TemplateList<'b>> {
let mut templates = vec![];
templates.push(engine.get_template("something")?);
Ok(templates)
}
let engine = TemplateEngine::new();
engine.add_template("something", "some text")?;
let compiled = CompiledTemplates::try_new(engine, |engine| {
get_templates(engine)
});Implementations§
Source§impl CompiledTemplates
impl CompiledTemplates
Sourcepub fn new(
owner: TemplateEngine,
dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> TemplateList<'_q>,
) -> Self
pub fn new( owner: TemplateEngine, dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> TemplateList<'_q>, ) -> Self
Constructs a new self-referential struct.
The provided owner will be moved into a heap allocated box. Followed by construction
of the dependent value, by calling dependent_builder with a shared reference to the
owner that remains valid for the lifetime of the constructed struct.
Sourcepub fn try_new<Err>(
owner: TemplateEngine,
dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> Result<TemplateList<'_q>, Err>,
) -> Result<Self, Err>
pub fn try_new<Err>( owner: TemplateEngine, dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> Result<TemplateList<'_q>, Err>, ) -> Result<Self, Err>
Constructs a new self-referential struct or returns an error.
Consumes owner on error.
Sourcepub fn try_new_or_recover<Err>(
owner: TemplateEngine,
dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> Result<TemplateList<'_q>, Err>,
) -> Result<Self, (TemplateEngine, Err)>
pub fn try_new_or_recover<Err>( owner: TemplateEngine, dependent_builder: impl for<'_q> FnOnce(&'_q TemplateEngine) -> Result<TemplateList<'_q>, Err>, ) -> Result<Self, (TemplateEngine, Err)>
Constructs a new self-referential struct or returns an error.
Returns owner and error as tuple on error.
Sourcepub fn borrow_owner<'_q>(&'_q self) -> &'_q TemplateEngine
pub fn borrow_owner<'_q>(&'_q self) -> &'_q TemplateEngine
Borrows owner.
Sourcepub fn with_dependent<'outer_fn, Ret>(
&'outer_fn self,
func: impl for<'_q> FnOnce(&'_q TemplateEngine, &'outer_fn TemplateList<'_q>) -> Ret,
) -> Ret
pub fn with_dependent<'outer_fn, Ret>( &'outer_fn self, func: impl for<'_q> FnOnce(&'_q TemplateEngine, &'outer_fn TemplateList<'_q>) -> Ret, ) -> Ret
Calls given closure func with a shared reference to dependent.
Sourcepub fn with_dependent_mut<'outer_fn, Ret>(
&'outer_fn mut self,
func: impl for<'_q> FnOnce(&'_q TemplateEngine, &'outer_fn mut TemplateList<'_q>) -> Ret,
) -> Ret
pub fn with_dependent_mut<'outer_fn, Ret>( &'outer_fn mut self, func: impl for<'_q> FnOnce(&'_q TemplateEngine, &'outer_fn mut TemplateList<'_q>) -> Ret, ) -> Ret
Calls given closure func with an unique reference to dependent.
Sourcepub fn borrow_dependent<'_q>(&'_q self) -> &'_q TemplateList<'_q>
pub fn borrow_dependent<'_q>(&'_q self) -> &'_q TemplateList<'_q>
Borrows dependent.
Sourcepub fn into_owner(self) -> TemplateEngine
pub fn into_owner(self) -> TemplateEngine
Consumes self and returns the the owner.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CompiledTemplates
impl !RefUnwindSafe for CompiledTemplates
impl Send for CompiledTemplates
impl Sync for CompiledTemplates
impl Unpin for CompiledTemplates
impl !UnwindSafe for CompiledTemplates
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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