moonpool_sim/observability/query.rs
1//! Read-side trait used by invariants to inspect captured trace events.
2//!
3//! [`TraceQuery`] is dyn-safe so invariants can take `&dyn TraceQuery`.
4//! Events are keyed by their name (the `tracing` message), mirroring how a
5//! production trace store is queried by event name. Typed values are
6//! extracted per field via the accessors on
7//! [`TraceEvent`](super::event::TraceEvent).
8
9use std::cell::Cell;
10
11use super::event::TraceEvent;
12
13/// Read-only view of captured trace events provided to invariants.
14pub trait TraceQuery {
15 /// Total number of events captured under `name`.
16 fn len(&self, name: &str) -> usize;
17
18 /// Return clones of events named `name` past `cursor`, and advance the
19 /// cursor to the new end.
20 ///
21 /// Cursors index into the per-name event list and stay stable within a
22 /// seed; reset them in [`Invariant::reset`](super::Invariant::reset).
23 fn since(&self, name: &str, cursor: &Cell<usize>) -> Vec<TraceEvent>;
24
25 /// All events captured under `name` since the start of the seed.
26 /// Convenience for full re-scans; prefer [`since`](Self::since) when an
27 /// incremental cursor will do.
28 fn snapshot(&self, name: &str) -> Vec<TraceEvent>;
29}