From 1b78fb5b5d1abf926041904a2b38fe4c826af363 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 3 Feb 2023 19:42:03 +0900 Subject: [PATCH] templater: add shorthand for Result This will appear in "impl Fn(..) -> .." and we can't alias it. --- src/template_parser.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/template_parser.rs b/src/template_parser.rs index 9032da552..b4c9b6ebb 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -38,6 +38,8 @@ use crate::{cli_util, time_util}; #[grammar = "template.pest"] pub struct TemplateParser; +type TemplateParseResult = Result; + #[derive(Clone, Debug)] pub struct TemplateParseError { kind: TemplateParseErrorKind, @@ -289,7 +291,7 @@ impl<'a, C: 'a> Expression<'a, C> { fn parse_method_chain<'a, I: 'a>( pair: Pair, input_property: PropertyAndLabels<'a, I>, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { let PropertyAndLabels(mut property, mut labels) = input_property; assert_eq!(pair.as_rule(), Rule::maybe_method); for chain in pair.into_inner() { @@ -325,7 +327,7 @@ fn parse_method_chain<'a, I: 'a>( fn parse_string_method<'a>( name: Pair, _args: Pairs, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { fn wrap_fn<'a, O>( f: impl Fn(&String) -> O + 'a, ) -> Box + 'a> { @@ -344,14 +346,14 @@ fn parse_string_method<'a>( fn parse_boolean_method<'a>( name: Pair, _args: Pairs, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { Err(TemplateParseError::no_such_method("Boolean", &name)) } fn parse_commit_or_change_id_method<'a>( name: Pair, _args: Pairs, -) -> Result>, TemplateParseError> { +) -> TemplateParseResult>> { fn wrap_fn<'a, O>( f: impl Fn(&CommitOrChangeId<'a>) -> O + 'a, ) -> Box, Output = O> + 'a> { @@ -379,7 +381,7 @@ fn parse_commit_or_change_id_method<'a>( fn parse_signature_method<'a>( name: Pair, _args: Pairs, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { fn wrap_fn<'a, O>( f: impl Fn(&Signature) -> O + 'a, ) -> Box + 'a> { @@ -398,7 +400,7 @@ fn parse_signature_method<'a>( fn parse_timestamp_method<'a>( name: Pair, _args: Pairs, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { fn wrap_fn<'a, O>( f: impl Fn(&Timestamp) -> O + 'a, ) -> Box + 'a> { @@ -416,7 +418,7 @@ fn parse_commit_keyword<'a>( repo: RepoRef<'a>, workspace_id: &WorkspaceId, pair: Pair, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { fn wrap_fn<'a, O>( f: impl Fn(&Commit) -> O + 'a, ) -> Box + 'a> { @@ -464,7 +466,7 @@ fn parse_commit_term<'a>( repo: RepoRef<'a>, workspace_id: &WorkspaceId, pair: Pair, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { assert_eq!(pair.as_rule(), Rule::term); let mut inner = pair.into_inner(); let expr = inner.next().unwrap(); @@ -570,7 +572,7 @@ fn parse_commit_template_rule<'a>( repo: RepoRef<'a>, workspace_id: &WorkspaceId, pair: Pair, -) -> Result, TemplateParseError> { +) -> TemplateParseResult> { assert_eq!(pair.as_rule(), Rule::template); let inner = pair.into_inner(); let mut expressions: Vec<_> = inner @@ -588,7 +590,7 @@ pub fn parse_commit_template<'a>( repo: RepoRef<'a>, workspace_id: &WorkspaceId, template_text: &str, -) -> Result + 'a>, TemplateParseError> { +) -> TemplateParseResult + 'a>> { let mut pairs: Pairs = TemplateParser::parse(Rule::program, template_text)?; let first_pair = pairs.next().unwrap(); if first_pair.as_rule() == Rule::EOI {