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