Simplify counting a bit

This commit is contained in:
Laurenz 2023-11-24 14:50:40 +01:00
parent 704bec64ae
commit 3d2f1d2d6c

View File

@ -284,12 +284,9 @@ impl Counter {
} }
} }
if let Some(update) = match elem.to::<UpdateElem>() { if let Some(update) = match elem.with::<dyn Count>() {
Some(elem) => Some(elem.update().clone()), Some(countable) => countable.update(),
None => match elem.with::<dyn Count>() { None => Some(CounterUpdate::Step(NonZeroUsize::ONE)),
Some(countable) => countable.update().clone(),
None => Some(CounterUpdate::Step(NonZeroUsize::ONE)),
},
} { } {
state.update(&mut vt, update)?; state.update(&mut vt, update)?;
} }
@ -647,7 +644,7 @@ impl Show for DisplayElem {
} }
/// Executes an update of a counter. /// Executes an update of a counter.
#[elem(Locatable, Show)] #[elem(Locatable, Show, Count)]
struct UpdateElem { struct UpdateElem {
/// The key that identifies the counter. /// The key that identifies the counter.
#[required] #[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 /// An specialized handler of the page counter that tracks both the physical
/// and the logical page counter. /// and the logical page counter.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]