diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 68c9550b7..a3ea18196 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -359,118 +359,119 @@ impl<'repo> CommitTemplateLanguage<'repo> { self.cache_extensions.get::() } + // TODO: delete pub fn wrap_commit( property: BoxedTemplateProperty<'repo, Commit>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::Commit(property) + CommitTemplatePropertyKind::wrap_commit(property) } pub fn wrap_commit_opt( property: BoxedTemplateProperty<'repo, Option>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitOpt(property) + CommitTemplatePropertyKind::wrap_commit_opt(property) } pub fn wrap_commit_list( property: BoxedTemplateProperty<'repo, Vec>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitList(property) + CommitTemplatePropertyKind::wrap_commit_list(property) } pub fn wrap_commit_ref( property: BoxedTemplateProperty<'repo, Rc>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitRef(property) + CommitTemplatePropertyKind::wrap_commit_ref(property) } pub fn wrap_commit_ref_opt( property: BoxedTemplateProperty<'repo, Option>>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitRefOpt(property) + CommitTemplatePropertyKind::wrap_commit_ref_opt(property) } pub fn wrap_commit_ref_list( property: BoxedTemplateProperty<'repo, Vec>>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitRefList(property) + CommitTemplatePropertyKind::wrap_commit_ref_list(property) } pub fn wrap_repo_path( property: BoxedTemplateProperty<'repo, RepoPathBuf>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::RepoPath(property) + CommitTemplatePropertyKind::wrap_repo_path(property) } pub fn wrap_repo_path_opt( property: BoxedTemplateProperty<'repo, Option>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::RepoPathOpt(property) + CommitTemplatePropertyKind::wrap_repo_path_opt(property) } pub fn wrap_commit_or_change_id( property: BoxedTemplateProperty<'repo, CommitOrChangeId>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CommitOrChangeId(property) + CommitTemplatePropertyKind::wrap_commit_or_change_id(property) } pub fn wrap_shortest_id_prefix( property: BoxedTemplateProperty<'repo, ShortestIdPrefix>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::ShortestIdPrefix(property) + CommitTemplatePropertyKind::wrap_shortest_id_prefix(property) } pub fn wrap_tree_diff( property: BoxedTemplateProperty<'repo, TreeDiff>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::TreeDiff(property) + CommitTemplatePropertyKind::wrap_tree_diff(property) } pub fn wrap_tree_diff_entry( property: BoxedTemplateProperty<'repo, TreeDiffEntry>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::TreeDiffEntry(property) + CommitTemplatePropertyKind::wrap_tree_diff_entry(property) } pub fn wrap_tree_diff_entry_list( property: BoxedTemplateProperty<'repo, Vec>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::TreeDiffEntryList(property) + CommitTemplatePropertyKind::wrap_tree_diff_entry_list(property) } pub fn wrap_tree_entry( property: BoxedTemplateProperty<'repo, TreeEntry>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::TreeEntry(property) + CommitTemplatePropertyKind::wrap_tree_entry(property) } pub fn wrap_diff_stats( property: BoxedTemplateProperty<'repo, DiffStatsFormatted<'repo>>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::DiffStats(property) + CommitTemplatePropertyKind::wrap_diff_stats(property) } fn wrap_cryptographic_signature_opt( property: BoxedTemplateProperty<'repo, Option>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::CryptographicSignatureOpt(property) + CommitTemplatePropertyKind::wrap_cryptographic_signature_opt(property) } pub fn wrap_annotation_line( property: BoxedTemplateProperty<'repo, AnnotationLine>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::AnnotationLine(property) + CommitTemplatePropertyKind::wrap_annotation_line(property) } pub fn wrap_trailer( property: BoxedTemplateProperty<'repo, Trailer>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::Trailer(property) + CommitTemplatePropertyKind::wrap_trailer(property) } pub fn wrap_trailer_list( property: BoxedTemplateProperty<'repo, Vec>, ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::TrailerList(property) + CommitTemplatePropertyKind::wrap_trailer_list(property) } } @@ -497,6 +498,32 @@ pub enum CommitTemplatePropertyKind<'repo> { TrailerList(BoxedTemplateProperty<'repo, Vec>), } +impl<'repo> CommitTemplatePropertyKind<'repo> { + template_builder::impl_wrap_property_fns!('repo, CommitTemplatePropertyKind, { + pub wrap_commit(Commit) => Commit, + pub wrap_commit_opt(Option) => CommitOpt, + pub wrap_commit_list(Vec) => CommitList, + pub wrap_commit_ref(Rc) => CommitRef, + pub wrap_commit_ref_opt(Option>) => CommitRefOpt, + pub wrap_commit_ref_list(Vec>) => CommitRefList, + pub wrap_repo_path(RepoPathBuf) => RepoPath, + pub wrap_repo_path_opt(Option) => RepoPathOpt, + pub wrap_commit_or_change_id(CommitOrChangeId) => CommitOrChangeId, + pub wrap_shortest_id_prefix(ShortestIdPrefix) => ShortestIdPrefix, + pub wrap_tree_diff(TreeDiff) => TreeDiff, + pub wrap_tree_diff_entry(TreeDiffEntry) => TreeDiffEntry, + pub wrap_tree_diff_entry_list(Vec) => TreeDiffEntryList, + pub wrap_tree_entry(TreeEntry) => TreeEntry, + pub wrap_diff_stats(DiffStatsFormatted<'repo>) => DiffStats, + pub wrap_cryptographic_signature_opt( + Option + ) => CryptographicSignatureOpt, + pub wrap_annotation_line(AnnotationLine) => AnnotationLine, + pub wrap_trailer(Trailer) => Trailer, + pub wrap_trailer_list(Vec) => TrailerList, + }); +} + impl<'repo> CoreTemplatePropertyVar<'repo> for CommitTemplatePropertyKind<'repo> { template_builder::impl_core_wrap_property_fns!('repo, CommitTemplatePropertyKind::Core); } diff --git a/cli/src/generic_templater.rs b/cli/src/generic_templater.rs index 24dbbe6fd..544e260ef 100644 --- a/cli/src/generic_templater.rs +++ b/cli/src/generic_templater.rs @@ -130,8 +130,9 @@ impl<'a, C> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C> { } impl<'a, C> GenericTemplateLanguage<'a, C> { + // TODO: delete pub fn wrap_self(property: BoxedTemplateProperty<'a, C>) -> GenericTemplatePropertyKind<'a, C> { - GenericTemplatePropertyKind::Self_(property) + GenericTemplatePropertyKind::wrap_self(property) } } @@ -140,6 +141,12 @@ pub enum GenericTemplatePropertyKind<'a, C> { Self_(BoxedTemplateProperty<'a, C>), } +impl<'a, C> GenericTemplatePropertyKind<'a, C> { + template_builder::impl_wrap_property_fns!('a, GenericTemplatePropertyKind, { + pub wrap_self(C) => Self_, + }); +} + impl<'a, C> CoreTemplatePropertyVar<'a> for GenericTemplatePropertyKind<'a, C> { template_builder::impl_core_wrap_property_fns!('a, GenericTemplatePropertyKind::Core); } diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index 13840834f..e16b2b9bd 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -135,16 +135,17 @@ impl OperationTemplateLanguage { self.cache_extensions.get::() } + // TODO: delete pub fn wrap_operation( property: BoxedTemplateProperty<'static, Operation>, ) -> OperationTemplatePropertyKind { - OperationTemplatePropertyKind::Operation(property) + OperationTemplatePropertyKind::wrap_operation(property) } pub fn wrap_operation_id( property: BoxedTemplateProperty<'static, OperationId>, ) -> OperationTemplatePropertyKind { - OperationTemplatePropertyKind::OperationId(property) + OperationTemplatePropertyKind::wrap_operation_id(property) } } @@ -154,6 +155,13 @@ pub enum OperationTemplatePropertyKind { OperationId(BoxedTemplateProperty<'static, OperationId>), } +impl OperationTemplatePropertyKind { + template_builder::impl_wrap_property_fns!('static, OperationTemplatePropertyKind, { + pub wrap_operation(Operation) => Operation, + pub wrap_operation_id(OperationId) => OperationId, + }); +} + impl CoreTemplatePropertyVar<'static> for OperationTemplatePropertyKind { template_builder::impl_core_wrap_property_fns!('static, OperationTemplatePropertyKind::Core); } diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index b552bb7b3..7078ed9ce 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -175,9 +175,15 @@ macro_rules! impl_core_wrap_property_fns { } macro_rules! impl_wrap_property_fns { - ($a:lifetime, $kind:path, $outer:path, { $( $func:ident($ty:ty) => $var:ident, )+ }) => { + ($a:lifetime, $kind:path, { $($body:tt)* }) => { + $crate::template_builder::impl_wrap_property_fns!( + $a, $kind, std::convert::identity, { $($body)* }); + }; + ($a:lifetime, $kind:path, $outer:path, { + $( $vis:vis $func:ident($ty:ty) => $var:ident, )+ + }) => { $( - fn $func( + $vis fn $func( property: $crate::templater::BoxedTemplateProperty<$a, $ty>, ) -> Self { use $kind as Kind; // https://github.com/rust-lang/rust/issues/48067