pub trait MakeDefaultHandle {
type Out;
// Required method
fn make_default_handle(self) -> Self::Out;
}Expand description
The trait that allows to use a metrics exporter in GenericMetricLayer.
Required Associated Types§
Sourcetype Out
type Out
The type of the metrics handle to return from MetricLayerBuilder.
Required Methods§
Sourcefn make_default_handle(self) -> Self::Out
fn make_default_handle(self) -> Self::Out
The function that defines how to initialize a metric exporter by default.
§Example
use axum_prometheus::{MakeDefaultHandle, GenericMetricLayer};
pub struct MyHandle(pub String);
impl MakeDefaultHandle for MyHandle {
type Out = ();
fn make_default_handle(self) -> Self::Out {
// This is where you initialize and register everything you need.
// Notice that self is passed in by value.
}
}and then, to use it:
ⓘ
// Initialize the struct, then use `pair_from`.
let my_handle = MyHandle(String::from("localhost"));
let (layer, handle) = GenericMetricLayer::pair_from(my_handle);
// Or optionally if your custom struct implements `Default` too, you may call `pair`.
// That's going to use `MyHandle::default()`.
let (layer, handle) = GenericMetricLayer::<'_, _, MyHandle>::pair();