From 8226584ae96023fa9f067e282dde745b316e359b Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 25 Feb 2024 11:30:20 +0900 Subject: [PATCH] templater: inline parse_optional_integer() in method body If each method body is split to closure, this parse helper will no longer be able to capture the environment. --- cli/src/commit_templater.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 26ef58b78..8f1e26d77 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -706,15 +706,12 @@ fn build_commit_or_change_id_method<'repo>( self_property: impl TemplateProperty + 'repo, function: &FunctionCallNode, ) -> TemplateParseResult> { - let parse_optional_integer = |function| -> Result, TemplateParseError> { - let ([], [len_node]) = template_parser::expect_arguments(function)?; - len_node - .map(|node| template_builder::expect_integer_expression(language, build_ctx, node)) - .transpose() - }; let property = match function.name { "short" => { - let len_property = parse_optional_integer(function)?; + let ([], [len_node]) = template_parser::expect_arguments(function)?; + let len_property = len_node + .map(|node| template_builder::expect_integer_expression(language, build_ctx, node)) + .transpose()?; language.wrap_string(TemplateFunction::new( (self_property, len_property), |(id, len)| id.short(len.map_or(12, |l| l.try_into().unwrap_or(0))), @@ -722,7 +719,10 @@ fn build_commit_or_change_id_method<'repo>( } "shortest" => { let id_prefix_context = &language.id_prefix_context; - let len_property = parse_optional_integer(function)?; + let ([], [len_node]) = template_parser::expect_arguments(function)?; + let len_property = len_node + .map(|node| template_builder::expect_integer_expression(language, build_ctx, node)) + .transpose()?; language.wrap_shortest_id_prefix(TemplateFunction::new( (self_property, len_property), |(id, len)| {