@@ -7,7 +7,7 @@ use crate::encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder};
77use super :: { MetricType , TypedMetric } ;
88use parking_lot:: { MappedRwLockReadGuard , RwLock , RwLockReadGuard , RwLockWriteGuard } ;
99use std:: cell:: RefCell ;
10- use std:: collections:: HashMap ;
10+ use std:: collections:: BTreeMap ;
1111use std:: sync:: Arc ;
1212
1313/// Representation of the OpenMetrics *MetricFamily* data type.
@@ -69,12 +69,12 @@ use std::sync::Arc;
6969/// # use std::io::Write;
7070/// #
7171/// # let mut registry = Registry::default();
72- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
72+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelSet)]
7373/// struct Labels {
7474/// method: Method,
7575/// };
7676///
77- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
77+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelValue)]
7878/// enum Method {
7979/// GET,
8080/// PUT,
@@ -100,9 +100,8 @@ use std::sync::Arc;
100100/// # "# EOF\n";
101101/// # assert_eq!(expected, buffer);
102102/// ```
103- // TODO: Consider exposing hash algorithm.
104103pub struct Family < S , M , C = fn ( ) -> M > {
105- metrics : Arc < RwLock < HashMap < S , M > > > ,
104+ metrics : Arc < RwLock < BTreeMap < S , M > > > ,
106105 /// Function that when called constructs a new metric.
107106 ///
108107 /// For most metric types this would simply be its [`Default`]
@@ -169,7 +168,7 @@ impl<M, F: Fn() -> M> MetricConstructor<M> for F {
169168 }
170169}
171170
172- impl < S : Clone + std :: hash :: Hash + Eq , M : Default > Default for Family < S , M > {
171+ impl < S : Clone + Eq , M : Default > Default for Family < S , M > {
173172 fn default ( ) -> Self {
174173 Self {
175174 metrics : Arc :: new ( RwLock :: new ( Default :: default ( ) ) ) ,
@@ -178,7 +177,7 @@ impl<S: Clone + std::hash::Hash + Eq, M: Default> Default for Family<S, M> {
178177 }
179178}
180179
181- impl < S : Clone + std :: hash :: Hash + Eq , M , C > Family < S , M , C > {
180+ impl < S : Clone + Eq , M , C > Family < S , M , C > {
182181 /// Create a metric family using a custom constructor to construct new
183182 /// metrics.
184183 ///
@@ -208,7 +207,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C> Family<S, M, C> {
208207 }
209208}
210209
211- impl < S : Clone + std :: hash :: Hash + Eq , M , C : MetricConstructor < M > > Family < S , M , C > {
210+ impl < S : Clone + Eq + Ord , M , C : MetricConstructor < M > > Family < S , M , C > {
212211 /// Access a metric with the given label set, creating it if one does not
213212 /// yet exist.
214213 ///
@@ -289,7 +288,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
289288 self . metrics . write ( ) . clear ( )
290289 }
291290
292- pub ( crate ) fn read ( & self ) -> RwLockReadGuard < HashMap < S , M > > {
291+ pub ( crate ) fn read ( & self ) -> RwLockReadGuard < BTreeMap < S , M > > {
293292 self . metrics . read ( )
294293 }
295294}
@@ -309,7 +308,7 @@ impl<S, M: TypedMetric, C> TypedMetric for Family<S, M, C> {
309308
310309impl < S , M , C > EncodeMetric for Family < S , M , C >
311310where
312- S : Clone + std :: hash :: Hash + Eq + EncodeLabelSet ,
311+ S : Clone + Eq + Ord + EncodeLabelSet ,
313312 M : EncodeMetric + TypedMetric ,
314313 C : MetricConstructor < M > ,
315314{
0 commit comments