diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 072265b56..68c9550b7 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -79,6 +79,7 @@ use crate::template_builder::merge_fn_map; use crate::template_builder::BuildContext; use crate::template_builder::CoreTemplateBuildFnTable; use crate::template_builder::CoreTemplatePropertyKind; +use crate::template_builder::CoreTemplatePropertyVar; use crate::template_builder::IntoTemplateProperty; use crate::template_builder::TemplateBuildMethodFnMap; use crate::template_builder::TemplateLanguage; @@ -164,8 +165,6 @@ impl<'repo> CommitTemplateLanguage<'repo> { impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { type Property = CommitTemplatePropertyKind<'repo>; - template_builder::impl_core_wrap_property_fns!('repo, CommitTemplatePropertyKind::Core); - fn settings(&self) -> &UserSettings { self.repo.base_repo().settings() } @@ -498,6 +497,10 @@ pub enum CommitTemplatePropertyKind<'repo> { TrailerList(BoxedTemplateProperty<'repo, Vec>), } +impl<'repo> CoreTemplatePropertyVar<'repo> for CommitTemplatePropertyKind<'repo> { + template_builder::impl_core_wrap_property_fns!('repo, CommitTemplatePropertyKind::Core); +} + impl<'repo> IntoTemplateProperty<'repo> for CommitTemplatePropertyKind<'repo> { fn type_name(&self) -> &'static str { match self { diff --git a/cli/src/generic_templater.rs b/cli/src/generic_templater.rs index be1f38ec7..24dbbe6fd 100644 --- a/cli/src/generic_templater.rs +++ b/cli/src/generic_templater.rs @@ -21,6 +21,7 @@ use crate::template_builder; use crate::template_builder::BuildContext; use crate::template_builder::CoreTemplateBuildFnTable; use crate::template_builder::CoreTemplatePropertyKind; +use crate::template_builder::CoreTemplatePropertyVar; use crate::template_builder::IntoTemplateProperty; use crate::template_builder::TemplateLanguage; use crate::template_parser; @@ -90,8 +91,6 @@ impl<'a, C> GenericTemplateLanguage<'a, C> { impl<'a, C> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C> { type Property = GenericTemplatePropertyKind<'a, C>; - template_builder::impl_core_wrap_property_fns!('a, GenericTemplatePropertyKind::Core); - fn settings(&self) -> &UserSettings { &self.settings } @@ -141,6 +140,10 @@ pub enum GenericTemplatePropertyKind<'a, C> { Self_(BoxedTemplateProperty<'a, C>), } +impl<'a, C> CoreTemplatePropertyVar<'a> for GenericTemplatePropertyKind<'a, C> { + template_builder::impl_core_wrap_property_fns!('a, GenericTemplatePropertyKind::Core); +} + impl<'a, C> IntoTemplateProperty<'a> for GenericTemplatePropertyKind<'a, C> { fn type_name(&self) -> &'static str { match self { diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index bee22dc93..13840834f 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -30,6 +30,7 @@ use crate::template_builder::merge_fn_map; use crate::template_builder::BuildContext; use crate::template_builder::CoreTemplateBuildFnTable; use crate::template_builder::CoreTemplatePropertyKind; +use crate::template_builder::CoreTemplatePropertyVar; use crate::template_builder::IntoTemplateProperty; use crate::template_builder::TemplateBuildMethodFnMap; use crate::template_builder::TemplateLanguage; @@ -88,8 +89,6 @@ impl OperationTemplateLanguage { impl TemplateLanguage<'static> for OperationTemplateLanguage { type Property = OperationTemplatePropertyKind; - template_builder::impl_core_wrap_property_fns!('static, OperationTemplatePropertyKind::Core); - fn settings(&self) -> &UserSettings { self.repo_loader.settings() } @@ -155,6 +154,10 @@ pub enum OperationTemplatePropertyKind { OperationId(BoxedTemplateProperty<'static, OperationId>), } +impl CoreTemplatePropertyVar<'static> for OperationTemplatePropertyKind { + template_builder::impl_core_wrap_property_fns!('static, OperationTemplatePropertyKind::Core); +} + impl IntoTemplateProperty<'static> for OperationTemplatePropertyKind { fn type_name(&self) -> &'static str { match self { diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index c0eb6c183..b552bb7b3 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -68,22 +68,50 @@ use crate::time_util; /// Callbacks to build language-specific evaluation objects from AST nodes. pub trait TemplateLanguage<'a> { - type Property: IntoTemplateProperty<'a>; + type Property: CoreTemplatePropertyVar<'a> + IntoTemplateProperty<'a>; - fn wrap_string(property: BoxedTemplateProperty<'a, String>) -> Self::Property; - fn wrap_string_list(property: BoxedTemplateProperty<'a, Vec>) -> Self::Property; - fn wrap_boolean(property: BoxedTemplateProperty<'a, bool>) -> Self::Property; - fn wrap_integer(property: BoxedTemplateProperty<'a, i64>) -> Self::Property; - fn wrap_integer_opt(property: BoxedTemplateProperty<'a, Option>) -> Self::Property; - fn wrap_config_value(property: BoxedTemplateProperty<'a, ConfigValue>) -> Self::Property; - fn wrap_signature(property: BoxedTemplateProperty<'a, Signature>) -> Self::Property; - fn wrap_email(property: BoxedTemplateProperty<'a, Email>) -> Self::Property; - fn wrap_size_hint(property: BoxedTemplateProperty<'a, SizeHint>) -> Self::Property; - fn wrap_timestamp(property: BoxedTemplateProperty<'a, Timestamp>) -> Self::Property; - fn wrap_timestamp_range(property: BoxedTemplateProperty<'a, TimestampRange>) -> Self::Property; + // TODO: delete + fn wrap_string(property: BoxedTemplateProperty<'a, String>) -> Self::Property { + Self::Property::wrap_string(property) + } + fn wrap_string_list(property: BoxedTemplateProperty<'a, Vec>) -> Self::Property { + Self::Property::wrap_string_list(property) + } + fn wrap_boolean(property: BoxedTemplateProperty<'a, bool>) -> Self::Property { + Self::Property::wrap_boolean(property) + } + fn wrap_integer(property: BoxedTemplateProperty<'a, i64>) -> Self::Property { + Self::Property::wrap_integer(property) + } + fn wrap_integer_opt(property: BoxedTemplateProperty<'a, Option>) -> Self::Property { + Self::Property::wrap_integer_opt(property) + } + fn wrap_config_value(property: BoxedTemplateProperty<'a, ConfigValue>) -> Self::Property { + Self::Property::wrap_config_value(property) + } + fn wrap_signature(property: BoxedTemplateProperty<'a, Signature>) -> Self::Property { + Self::Property::wrap_signature(property) + } + fn wrap_email(property: BoxedTemplateProperty<'a, Email>) -> Self::Property { + Self::Property::wrap_email(property) + } + fn wrap_size_hint(property: BoxedTemplateProperty<'a, SizeHint>) -> Self::Property { + Self::Property::wrap_size_hint(property) + } + fn wrap_timestamp(property: BoxedTemplateProperty<'a, Timestamp>) -> Self::Property { + Self::Property::wrap_timestamp(property) + } + fn wrap_timestamp_range(property: BoxedTemplateProperty<'a, TimestampRange>) -> Self::Property { + Self::Property::wrap_timestamp_range(property) + } - fn wrap_template(template: Box) -> Self::Property; - fn wrap_list_template(template: Box) -> Self::Property; + // TODO: delete + fn wrap_template(template: Box) -> Self::Property { + Self::Property::wrap_template(template) + } + fn wrap_list_template(template: Box) -> Self::Property { + Self::Property::wrap_list_template(template) + } fn settings(&self) -> &UserSettings; @@ -107,7 +135,7 @@ pub trait TemplateLanguage<'a> { ) -> TemplateParseResult; } -/// Implements `TemplateLanguage::wrap_()` functions. +/// Implements `CoreTemplatePropertyVar::wrap_()` functions. /// /// - `impl_core_wrap_property_fns('a)` for `CoreTemplatePropertyKind`, /// - `impl_core_wrap_property_fns('a, MyKind::Core)` for `MyKind::Core(..)`. @@ -133,13 +161,13 @@ macro_rules! impl_core_wrap_property_fns { ); fn wrap_template( template: Box, - ) -> Self::Property { + ) -> Self { use $crate::template_builder::CoreTemplatePropertyKind as Kind; $outer(Kind::Template(template)) } fn wrap_list_template( template: Box, - ) -> Self::Property { + ) -> Self { use $crate::template_builder::CoreTemplatePropertyKind as Kind; $outer(Kind::ListTemplate(template)) } @@ -151,7 +179,7 @@ macro_rules! impl_wrap_property_fns { $( fn $func( property: $crate::templater::BoxedTemplateProperty<$a, $ty>, - ) -> Self::Property { + ) -> Self { use $kind as Kind; // https://github.com/rust-lang/rust/issues/48067 $outer(Kind::$var(property)) } @@ -162,7 +190,26 @@ macro_rules! impl_wrap_property_fns { pub(crate) use impl_core_wrap_property_fns; pub(crate) use impl_wrap_property_fns; +/// Wrapper for the core template property types. +pub trait CoreTemplatePropertyVar<'a> { + fn wrap_string(property: BoxedTemplateProperty<'a, String>) -> Self; + fn wrap_string_list(property: BoxedTemplateProperty<'a, Vec>) -> Self; + fn wrap_boolean(property: BoxedTemplateProperty<'a, bool>) -> Self; + fn wrap_integer(property: BoxedTemplateProperty<'a, i64>) -> Self; + fn wrap_integer_opt(property: BoxedTemplateProperty<'a, Option>) -> Self; + fn wrap_config_value(property: BoxedTemplateProperty<'a, ConfigValue>) -> Self; + fn wrap_signature(property: BoxedTemplateProperty<'a, Signature>) -> Self; + fn wrap_email(property: BoxedTemplateProperty<'a, Email>) -> Self; + fn wrap_size_hint(property: BoxedTemplateProperty<'a, SizeHint>) -> Self; + fn wrap_timestamp(property: BoxedTemplateProperty<'a, Timestamp>) -> Self; + fn wrap_timestamp_range(property: BoxedTemplateProperty<'a, TimestampRange>) -> Self; + + fn wrap_template(template: Box) -> Self; + fn wrap_list_template(template: Box) -> Self; +} + /// Provides access to basic template property types. +// TODO: merge with CoreTemplatePropertyVar<'a>? pub trait IntoTemplateProperty<'a> { /// Type name of the property output. fn type_name(&self) -> &'static str;