1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
use crate::MetricKind; use metrics::Key; /// A composite key that stores both the metric key and the metric kind. /// /// This type is intended to be used by recorders that internally take advantage of /// the provided [`Registry`](crate::registry::Registry) type when also using /// [`Handle`](crate::handle::Handle). /// /// Since handles are opaque, having the standard key by itself could lead to two /// different metric kinds tryin to use the same key, calling read or write methods /// that inevitably panic. With `CompositeKey`, the kind can tied to the underlying /// handle, ensuring parity between the two. #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct CompositeKey(MetricKind, Key); impl CompositeKey { /// Creates a new `CompositeKey`. pub const fn new(kind: MetricKind, key: Key) -> CompositeKey { CompositeKey(kind, key) } /// Gets the inner key represented by this `CompositeKey`. pub fn key(&self) -> &Key { &self.1 } /// Gets the inner kind represented by this `CompositeKey`. pub fn kind(&self) -> MetricKind { self.0 } /// Takes the individual pieces of this `CompositeKey`. pub fn into_parts(self) -> (MetricKind, Key) { (self.0, self.1) } }