From 0cef90f4f450e8d44a2cab3f937eff13c9d7b728 Mon Sep 17 00:00:00 2001 From: dploch Date: Thu, 25 Apr 2024 13:02:29 -0400 Subject: [PATCH] examples: simplify commit templater example with Default --- cli/examples/custom-commit-templater/main.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cli/examples/custom-commit-templater/main.rs b/cli/examples/custom-commit-templater/main.rs index 181438dff..bdc31f73e 100644 --- a/cli/examples/custom-commit-templater/main.rs +++ b/cli/examples/custom-commit-templater/main.rs @@ -49,17 +49,12 @@ fn num_char_in_id(commit: Commit, ch_match: char) -> i64 { count } +#[derive(Default)] struct MostDigitsInId { count: OnceCell, } impl MostDigitsInId { - fn new() -> Self { - Self { - count: OnceCell::new(), - } - } - fn count(&self, repo: &dyn Repo) -> i64 { *self.count.get_or_init(|| { RevsetExpression::all() @@ -125,7 +120,7 @@ impl CommitTemplateLanguageExtension for HexCounter { } fn build_cache_extensions(&self, extensions: &mut ExtensionsMap) { - extensions.insert(MostDigitsInId::new()); + extensions.insert(MostDigitsInId::default()); } }