Trait Trace
pub trait Trace: Send + Sync {
// Required methods
fn add_trace_sink(
&self,
sink: Arc<dyn Fn(&TraceEvent) + Sync + Send>,
) -> Observing;
fn observers(&self) -> usize;
}Expand description
A capability of a bus (BusTrace::trace): every emit, listener run,
ask and drain reported to the sinks observing it, as it happens.
What an implementation promises:
- With no sink observing, nothing is built or recorded: an emit costs at most a relaxed atomic load more.
- Each event goes to every sink observing when it is made, once, on
the thread that made it, with a capture number greater than every
number given before by the same bus (
TraceEvent::capture). - Events a sink causes on its own thread while it runs (a sink that emits) are not reported: a sink never hears itself.
- A sink that panics is ignored; the emit goes on.
- Dropping the
Observingguard removes its sink: once the drop returns, the sink is called no more by this thread, andTrace::observerscounts it no more.
Required Methods§
fn add_trace_sink(
&self,
sink: Arc<dyn Fn(&TraceEvent) + Sync + Send>,
) -> Observing
fn add_trace_sink( &self, sink: Arc<dyn Fn(&TraceEvent) + Sync + Send>, ) -> Observing
Adds a sink; it observes until the guard is dropped.
Implementations§
§impl<'a> dyn Trace + 'a
impl<'a> dyn Trace + 'a
pub fn observe(
&self,
sink: impl Fn(&TraceEvent) + Send + Sync + 'static,
) -> Observing
pub fn observe( &self, sink: impl Fn(&TraceEvent) + Send + Sync + 'static, ) -> Observing
Observes the bus with sink until the guard is dropped
(Trace::add_trace_sink).