summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-11-24 14:50:40 +0100
committerLaurenz <laurmaedje@gmail.com>2023-11-24 14:54:43 +0100
commit3d2f1d2d6cc34fa64c56abd335dd14ea4c932a6c (patch)
treef7e9da9a96f43a225c7aafd31e466a9748ee8db5
parent704bec64ae000699874cbbb9b08fd27fca4d8f10 (diff)
Simplify counting a bit
-rw-r--r--crates/typst/src/introspection/counter.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/typst/src/introspection/counter.rs b/crates/typst/src/introspection/counter.rs
index 16403320..7b073681 100644
--- a/crates/typst/src/introspection/counter.rs
+++ b/crates/typst/src/introspection/counter.rs
@@ -284,12 +284,9 @@ impl Counter {
}
}
- if let Some(update) = match elem.to::<UpdateElem>() {
- Some(elem) => Some(elem.update().clone()),
- None => match elem.with::<dyn Count>() {
- Some(countable) => countable.update().clone(),
- None => Some(CounterUpdate::Step(NonZeroUsize::ONE)),
- },
+ if let Some(update) = match elem.with::<dyn Count>() {
+ Some(countable) => countable.update(),
+ None => Some(CounterUpdate::Step(NonZeroUsize::ONE)),
} {
state.update(&mut vt, update)?;
}
@@ -647,7 +644,7 @@ impl Show for DisplayElem {
}
/// Executes an update of a counter.
-#[elem(Locatable, Show)]
+#[elem(Locatable, Show, Count)]
struct UpdateElem {
/// The key that identifies the counter.
#[required]
@@ -665,6 +662,12 @@ impl Show for UpdateElem {
}
}
+impl Count for UpdateElem {
+ fn update(&self) -> Option<CounterUpdate> {
+ Some(self.update.clone())
+ }
+}
+
/// An specialized handler of the page counter that tracks both the physical
/// and the logical page counter.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]