Skip to content

Commit

Permalink
examples: simplify commit templater example with Default
Browse files Browse the repository at this point in the history
  • Loading branch information
torquestomp committed Apr 26, 2024
1 parent d7b4e38 commit 234f19f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cli/examples/custom-commit-templater/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ fn num_char_in_id(commit: Commit, ch_match: char) -> i64 {
count
}

#[derive(Default)]
struct MostDigitsInId {
count: OnceCell<i64>,
}

impl MostDigitsInId {
fn new() -> Self {
Self {
count: OnceCell::new(),
}
}

fn count(&self, repo: &dyn Repo) -> i64 {
*self.count.get_or_init(|| {
RevsetExpression::all()
Expand Down Expand Up @@ -125,7 +120,7 @@ impl CommitTemplateLanguageExtension for HexCounter {
}

fn build_cache_extensions(&self, extensions: &mut ExtensionsMap) {
extensions.insert(MostDigitsInId::new());
extensions.insert(MostDigitsInId::default());
}
}

Expand Down

0 comments on commit 234f19f

Please sign in to comment.