rrpack_prime/visual/counter/
tracer.rs1use super::state::*;
2use derive_more::{Deref, DerefMut};
3use rill_derive::TracerOpts;
4use rill_protocol::flow::core::FlowMode;
5use rrpack_basis::{AutoPath, BindedTracer};
6
7#[derive(TracerOpts, Clone, Default)]
8pub struct CounterOpts {}
9
10impl From<CounterOpts> for CounterSpec {
11 fn from(_opts: CounterOpts) -> Self {
12 Self {}
13 }
14}
15
16#[derive(Debug, Deref, DerefMut, Clone)]
17pub struct Counter {
18 tracer: BindedTracer<CounterState>,
19}
20
21impl Counter {
22 pub fn new(
23 auto_path: impl Into<AutoPath>,
24 mode: FlowMode,
25 spec: impl Into<CounterSpec>,
26 ) -> Self {
27 let tracer = BindedTracer::new(auto_path.into(), mode, spec.into());
28 Self { tracer }
29 }
30
31 pub fn inc(&self, delta: impl Into<i64>) {
32 let msg = CounterEvent::Inc {
33 delta: delta.into(),
34 };
35 self.tracer.send(msg, None);
36 }
37}