pub trait MetricsSink:
Send
+ Sync
+ 'static {
// Required methods
fn counter(&self, name: &str, labels: &[(&str, &str)], value: u64);
fn gauge(&self, name: &str, labels: &[(&str, &str)], value: f64);
fn histogram(&self, name: &str, labels: &[(&str, &str)], value: f64);
// Provided method
fn inc(&self, name: &str) { ... }
}Expand description
Push-based metrics interface.
Implementors are called from the framework’s hot path on every observable event, so they must be fast and lock-light. Allocation per call is acceptable — the framework doesn’t claim a fixed per-event budget — but blocking on I/O is not. Async sinks should drop events into a channel and process them on a separate task.
Send + Sync + 'static so an Arc<dyn MetricsSink> lives across
supervised services.
§Example
A simple in-process counting sink, useful for tests and embedded dashboards.
use std::collections::HashMap;
use std::sync::Mutex;
use rustrade_core::MetricsSink;
#[derive(Default)]
struct CountingSink {
counters: Mutex<HashMap<String, u64>>,
}
impl MetricsSink for CountingSink {
fn counter(&self, name: &str, _labels: &[(&str, &str)], value: u64) {
*self.counters.lock().unwrap().entry(name.into()).or_insert(0) += value;
}
fn gauge(&self, _name: &str, _labels: &[(&str, &str)], _value: f64) {}
fn histogram(&self, _name: &str, _labels: &[(&str, &str)], _value: f64) {}
}
let sink = CountingSink::default();
sink.counter("rustrade_fills_routed_total", &[], 1);
sink.inc("rustrade_fills_routed_total");
assert_eq!(sink.counters.lock().unwrap()["rustrade_fills_routed_total"], 2);Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".