pub struct GenericTemplateLanguage<'a, C> { /* private fields */ }
Expand description
General-purpose template language for basic value types.
This template language only supports the core template property types (plus
the self type C
.) The self type C
is usually a tuple or struct of value
types. It’s cloned several times internally. Keyword functions need to be
registered to extract properties from the self object.
Implementations§
Source§impl<'a, C> GenericTemplateLanguage<'a, C>where
C: Serialize + 'a,
impl<'a, C> GenericTemplateLanguage<'a, C>where
C: Serialize + 'a,
Sourcepub fn new(settings: &UserSettings) -> Self
pub fn new(settings: &UserSettings) -> Self
Sets up environment with no keywords.
New keyword functions can be registered by add_keyword()
.
Sourcepub fn with_keywords(
keywords: GenericTemplateBuildKeywordFnMap<'a, C>,
settings: &UserSettings,
) -> Self
pub fn with_keywords( keywords: GenericTemplateBuildKeywordFnMap<'a, C>, settings: &UserSettings, ) -> Self
Sets up environment with the given keywords
table.
Sourcepub fn add_keyword<F>(&mut self, name: &'static str, build: F)where
F: Fn(BoxedTemplateProperty<'a, C>) -> TemplateParseResult<GenericTemplatePropertyKind<'a, C>> + 'a,
pub fn add_keyword<F>(&mut self, name: &'static str, build: F)where
F: Fn(BoxedTemplateProperty<'a, C>) -> TemplateParseResult<GenericTemplatePropertyKind<'a, C>> + 'a,
Registers new function that translates keyword to property.
A keyword function returns Self::Property
, which is basically a
closure tagged by its return type. The inner closure is usually wrapped
by TemplateFunction
.
ⓘ
language.add_keyword("name", |self_property| {
let out_property = self_property.map(|v| v.to_string());
Ok(out_property.into_dyn_wrapped())
});
Trait Implementations§
Source§impl<'a, C> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C>where
C: Serialize + 'a,
impl<'a, C> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C>where
C: Serialize + 'a,
type Property = GenericTemplatePropertyKind<'a, C>
fn settings(&self) -> &UserSettings
Source§fn build_function(
&self,
diagnostics: &mut TemplateDiagnostics,
build_ctx: &BuildContext<'_, Self::Property>,
function: &FunctionCallNode<'_>,
) -> TemplateParseResult<Self::Property>
fn build_function( &self, diagnostics: &mut TemplateDiagnostics, build_ctx: &BuildContext<'_, Self::Property>, function: &FunctionCallNode<'_>, ) -> TemplateParseResult<Self::Property>
Translates the given global
function
call to a property. Read moreSource§fn build_method(
&self,
diagnostics: &mut TemplateDiagnostics,
build_ctx: &BuildContext<'_, Self::Property>,
property: Self::Property,
function: &FunctionCallNode<'_>,
) -> TemplateParseResult<Self::Property>
fn build_method( &self, diagnostics: &mut TemplateDiagnostics, build_ctx: &BuildContext<'_, Self::Property>, property: Self::Property, function: &FunctionCallNode<'_>, ) -> TemplateParseResult<Self::Property>
Creates a method call thunk for the given
function
of the given
property
.Auto Trait Implementations§
impl<'a, C> Freeze for GenericTemplateLanguage<'a, C>
impl<'a, C> !RefUnwindSafe for GenericTemplateLanguage<'a, C>
impl<'a, C> !Send for GenericTemplateLanguage<'a, C>
impl<'a, C> !Sync for GenericTemplateLanguage<'a, C>
impl<'a, C> Unpin for GenericTemplateLanguage<'a, C>
impl<'a, C> !UnwindSafe for GenericTemplateLanguage<'a, C>
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
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>
Converts
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>
Converts
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