@@ -6,7 +6,7 @@ use crate::encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder};
66
77use super :: { MetricType , TypedMetric } ;
88use parking_lot:: { MappedRwLockReadGuard , RwLock , RwLockReadGuard , RwLockWriteGuard } ;
9- use std:: collections:: HashMap ;
9+ use std:: collections:: BTreeMap ;
1010use std:: sync:: Arc ;
1111
1212/// Representation of the OpenMetrics *MetricFamily* data type.
@@ -68,12 +68,12 @@ use std::sync::Arc;
6868/// # use std::io::Write;
6969/// #
7070/// # let mut registry = Registry::default();
71- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
71+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelSet)]
7272/// struct Labels {
7373/// method: Method,
7474/// };
7575///
76- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
76+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelValue)]
7777/// enum Method {
7878/// GET,
7979/// PUT,
@@ -99,9 +99,8 @@ use std::sync::Arc;
9999/// # "# EOF\n";
100100/// # assert_eq!(expected, buffer);
101101/// ```
102- // TODO: Consider exposing hash algorithm.
103102pub struct Family < S , M , C = fn ( ) -> M > {
104- metrics : Arc < RwLock < HashMap < S , M > > > ,
103+ metrics : Arc < RwLock < BTreeMap < S , M > > > ,
105104 /// Function that when called constructs a new metric.
106105 ///
107106 /// For most metric types this would simply be its [`Default`]
@@ -168,7 +167,7 @@ impl<M, F: Fn() -> M> MetricConstructor<M> for F {
168167 }
169168}
170169
171- impl < S : Clone + std :: hash :: Hash + Eq , M : Default > Default for Family < S , M > {
170+ impl < S : Clone + Eq , M : Default > Default for Family < S , M > {
172171 fn default ( ) -> Self {
173172 Self {
174173 metrics : Arc :: new ( RwLock :: new ( Default :: default ( ) ) ) ,
@@ -177,7 +176,7 @@ impl<S: Clone + std::hash::Hash + Eq, M: Default> Default for Family<S, M> {
177176 }
178177}
179178
180- impl < S : Clone + std :: hash :: Hash + Eq , M , C > Family < S , M , C > {
179+ impl < S : Clone + Eq , M , C > Family < S , M , C > {
181180 /// Create a metric family using a custom constructor to construct new
182181 /// metrics.
183182 ///
@@ -207,12 +206,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C> Family<S, M, C> {
207206 }
208207}
209208
210- impl < S : Clone + std:: hash:: Hash + Eq , M : Clone , C : MetricConstructor < M > > Family < S , M , C >
211- where
212- S : Clone + std:: hash:: Hash + Eq ,
213- M : Clone ,
214- C : MetricConstructor < M > ,
215- {
209+ impl < S : Clone + Eq + Ord , M : Clone , C : MetricConstructor < M > > Family < S , M , C > {
216210 /// Access a metric with the given label set, creating it if one does not yet exist.
217211 ///
218212 /// ```
@@ -241,7 +235,7 @@ where
241235 }
242236}
243237
244- impl < S : Clone + std :: hash :: Hash + Eq , M , C : MetricConstructor < M > > Family < S , M , C > {
238+ impl < S : Clone + Eq + Ord , M , C : MetricConstructor < M > > Family < S , M , C > {
245239 /// Access a metric with the given label set, creating it if one does not
246240 /// yet exist.
247241 ///
@@ -341,7 +335,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
341335 self . metrics . write ( ) . clear ( )
342336 }
343337
344- pub ( crate ) fn read ( & self ) -> RwLockReadGuard < ' _ , HashMap < S , M > > {
338+ pub ( crate ) fn read ( & self ) -> RwLockReadGuard < ' _ , BTreeMap < S , M > > {
345339 self . metrics . read ( )
346340 }
347341}
@@ -361,7 +355,7 @@ impl<S, M: TypedMetric, C> TypedMetric for Family<S, M, C> {
361355
362356impl < S , M , C > EncodeMetric for Family < S , M , C >
363357where
364- S : Clone + std :: hash :: Hash + Eq + EncodeLabelSet ,
358+ S : Clone + Eq + Ord + EncodeLabelSet ,
365359 M : EncodeMetric + TypedMetric ,
366360 C : MetricConstructor < M > ,
367361{
0 commit comments