saluki_metrics/lib.rs
1//! Metrics-related helpers and utilities.
2#![deny(warnings)]
3#![deny(missing_docs)]
4
5mod builder;
6mod derived;
7mod mapped;
8
9// The `metrics` handle types are re-exported so that structs using the `static_metrics` macro can name their fields
10// (`Counter`/`Gauge`/`Histogram`) via `saluki_metrics` without depending on `metrics` directly.
11pub use ::metrics::{Counter, Gauge, Histogram};
12pub use saluki_metrics_macros::static_metrics;
13
14pub use self::builder::{MetricTag, MetricsBuilder};
15pub use self::derived::{DerivedGauge, DerivedHistogram};
16pub use self::mapped::MappedMetric;
17
18#[cfg(any(test, feature = "test"))]
19pub mod test;
20
21// Lets unit tests in this crate use `static_metrics`, whose generated code refers to `::saluki_metrics`.
22#[cfg(test)]
23extern crate self as saluki_metrics;
24
25#[doc(hidden)]
26pub mod reexport {
27 pub use ::metrics;
28}
29
30/// A type that can be converted into a `SharedString`.
31///
32/// This is a blanket trait used to generically support converting any type which already supports conversion to
33/// `String` into a `SharedString`. This is purely used by the `static_metrics` macro to allow for ergonomic
34/// handling of labels, and should generally not need to be implemented manually.
35pub trait Stringable {
36 /// Converts the given value to a `SharedString`.
37 fn to_shared_string(&self) -> ::metrics::SharedString;
38}
39
40impl<T> Stringable for T
41where
42 T: std::fmt::Display,
43{
44 fn to_shared_string(&self) -> ::metrics::SharedString {
45 std::string::ToString::to_string(&self).into()
46 }
47}