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>
impl<'a, C> GenericTemplateLanguage<'a, C>
sourcepub fn new() -> Self
pub fn new() -> Self
Sets up environment with no keywords.
New keyword functions can be registered by add_keyword().
sourcepub fn with_keywords(keywords: GenericTemplateBuildKeywordFnMap<'a, C>) -> Self
pub fn with_keywords(keywords: GenericTemplateBuildKeywordFnMap<'a, C>) -> Self
Sets up environment with the given keywords table.
sourcepub fn add_keyword<F>(&mut self, name: &'static str, build: F)where
F: Fn(Box<dyn TemplateProperty<Output = C> + 'a>) -> TemplateParseResult<GenericTemplatePropertyKind<'a, C>> + 'a,
pub fn add_keyword<F>(&mut self, name: &'static str, build: F)where
F: Fn(Box<dyn TemplateProperty<Output = C> + 'a>) -> 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(GenericTemplateLanguage::wrap_string(out_property))
});source§impl<'a, C> GenericTemplateLanguage<'a, C>
impl<'a, C> GenericTemplateLanguage<'a, C>
pub fn wrap_self( property: impl TemplateProperty<Output = C> + 'a, ) -> GenericTemplatePropertyKind<'a, C>
Trait Implementations§
source§impl<'a, C: 'a> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C>
impl<'a, C: 'a> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C>
type Property = GenericTemplatePropertyKind<'a, C>
fn wrap_string( property: impl TemplateProperty<Output = String> + 'a, ) -> Self::Property
fn wrap_string_list( property: impl TemplateProperty<Output = Vec<String>> + 'a, ) -> Self::Property
fn wrap_boolean( property: impl TemplateProperty<Output = bool> + 'a, ) -> Self::Property
fn wrap_integer( property: impl TemplateProperty<Output = i64> + 'a, ) -> Self::Property
fn wrap_integer_opt( property: impl TemplateProperty<Output = Option<i64>> + 'a, ) -> Self::Property
fn wrap_signature( property: impl TemplateProperty<Output = Signature> + 'a, ) -> Self::Property
fn wrap_size_hint( property: impl TemplateProperty<Output = SizeHint> + 'a, ) -> Self::Property
fn wrap_timestamp( property: impl TemplateProperty<Output = Timestamp> + 'a, ) -> Self::Property
fn wrap_timestamp_range( property: impl TemplateProperty<Output = TimestampRange> + 'a, ) -> Self::Property
fn wrap_template(template: Box<dyn Template + 'a>) -> Self::Property
fn wrap_list_template(template: Box<dyn ListTemplate + 'a>) -> Self::Property
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 morefn build_method( &self, diagnostics: &mut TemplateDiagnostics, build_ctx: &BuildContext<'_, Self::Property>, property: Self::Property, function: &FunctionCallNode<'_>, ) -> TemplateParseResult<Self::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